How to get test coverage reported with tap testing esm?
module.exports.classify = (n) => {
if(n >= 2) return 'large'
return 'small'
}
using const tap = require('tap')
in test.js
to test, perfectly reports coverage:
❯ tap test.js
test.js
test(1)
✓ should be equal
test(2)
✓ should be equal
2 passing (504.939ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
export const classify = (n) => {
if(n >= 2) return 'large'
return 'small'
}
using import tap from 'tap'
in test.mjs
to test, reports no coverage at all:
❯ tap test.mjs
test.mjs
test(1)
✓ should be equal
test(2)
✓ should be equal
2 passing (254.006ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
with c8 wrapping tap, coverage metrics get reported natively (--no-coverage
option used to supress the empty tap report):
❯ c8 tap test.mjs --no-coverage
test.mjs
test(1)
✓ should be equal
test(2)
✓ should be equal
2 passing (187.043ms)
-----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.mjs | 100 | 100 | 100 | 100 |
-----------|---------|----------|---------|---------|-------------------