Started trying to integrate nyc/istambul into my ava test suites:
./node_modules/.bin/nyc --include modules/todo.js --es-modules ./node_modules/.bin/ava
1 tests passed
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
The output fails to list any of the files!
If I add the --all
flag I get the following even though the tests cover both functions:
ERROR: Coverage for lines (0%) does not meet global threshold (90%)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
todo.js | 0 | 0 | 0 | 0 | 6-30
----------|---------|----------|---------|---------|-------------------
So it looks as if the output from the ava
testing tool is not being picked up by the nyc
coverage tool.
The simple setup is as follows:
/* todo.js (uses ES6 modules) */
'use strict'
let data = []
function clear() {
data = []
}
function add(item, qty = 1) {
qty = Number(qty)
if(isNaN(qty)) throw new Error('qty must be a number')
data.push({item: item, qty: qty})
return true
}
export { add, clear }
/* todo.spec.js */
import { add, clear } from './modules/todo.js'
import test from 'ava'
test('add a single item', test => {
clear()
const ok = add('bread')
test.truthy(ok)
})
I tried creating a .nycrc.json
file but this didn't help:
{
"check-coverage": true,
"include": [
"modules/todo.js"
],
"reporter": ["text", "html"]
}