π©
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
Supertape
supports ESM
from the box;
mock-require (we in ESM
!);
π€·β How to mock modules without
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?
ESCover
! It supports loaders, ESM
and collects coverage as a loader!
Install
npm i escover -D
Run to collect and show coverage:
escover npm test
How it looks like?
When everything is covered:
When some lines missing coverage:
π©
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
This configuration will add coverage collectors and then apply mocks with help of mock-import
. Of course the most comfortable way of doing this things will be madrun. Run you package-scripts
in JavaScript
:)!
License
MIT