README
ESCover
🎩Coverage for EcmaScript Modules based on 🐊Putout
and loaders.
Why another coverage tool?
When you want to use ESM
in Node.js
without transpiling to CommonJS
(that's what jest
, ava
, tap
does),
you have a couple problems to solve.
CommonJS
?
🤷 What test runner does no transpiling to ☝️ that's easy! 📼 Supertape
supports ESM
from the box;
mock-require (we in ESM
!);
🤷 How to mock modules without ☝️ that's solved! mock-import
does the thing using loaders
;
nyc
doesn't supported?
🤷 How to get coverage when ☝️ c8
could help, but no it supports no query paramters
which are needed to load module again, and apply mocks.
🤷 How to get coverage when mocks are used?
☝️ Use 🎩ESCover
! It supports loaders, ESM
and collects coverage as a loader!
coveralls
? Does lcov
supported?
🤷 What with ☝️ Sure! coverage/lcov.info
is main coverage file for 🎩ESCover
.
Install
npm i escover -D
Run to collect and show coverage:
escover npm test
Config
exclude
section of configuration file .nyrc.json
supported.
How it looks like?
When everything is covered:
What formatters exists?
There is two types of formatters:
lines
adds links to each line;files
shows information in table;
You can choose formatter with ESCOVER_FORMAT
env variable.
ESCover
with mock-import
?
What if I want to use 🎩Experimental loaders
supports only one, for now. So zenload should be used.
Install it with:
npm i escover mock-import zenload
Then run:
NODE_OPTIONS="'--loader zenlend'" ZENLOAD='escover,mock-import' escover npm test
lcov
What you should know about Format used by 🎩ESCover
located in coverage/lcov.info
.
- ☝️
lcov
was created in2002
, almost twenty years ago. - ☝️ Linux kernel developers created it to know what is going on with the coverage.
- ☝️ It's written in
PERL
and has text based format. - ☝️ This is most popular coverage format of all times supported by a lot of tools (like coveralls).
When you run your ESM
application with:
escover npm test
You will receive something similar to:
SF:/Users/coderaiser/escover/lib/transform.js
DA:1,1
DA:3,1
DA:7,1
DA:9,1
DA:10,1
DA:12,1
DA:24,1
DA:25,1
DA:27,1
DA:28,1
DA:29,1
DA:32,1
end_of_record
Where:
SF
- is path to source;DA
- is line number, and count of running;end_of_record
latest recored for current file entry;
The only thing that is differ from lcov
: counters it 0
or 1
, if you have a reason to use "real" counters create an issue.
It can be added in one line of code, but I see no reason why it can be useful 🤷♂️.
License
MIT