I've typically used nyc to provide coverage for my unit tests. All honkey dorey for pre-ES6 require('myModule')
tests. I'm having trouble getting it to work with unit tests that use ES6 import. Tests without coverage work with --experimental-modules
and .mjs files:
package.json
"scripts": {
"test": "node --experimental-modules ./test/test.mjs",
... others deleted to save space
},
And everything works. I'm using Tape for testing if that matters. Output looks like:
(node:9360) ExperimentalWarning: The ESM module loader is experimental.
TAP version 13
# number
ok 1 should be equal
(... more deleted)
But when I try to use nyc, e.g. nyc --reporter=lcov --extension .mjs npm test
I get an error:
(node:7304) ExperimentalWarning: The ESM module loader is experimental.
Error [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension: C:/Users/Morgan/.node-spawn-wrap-6952-61a26e1bb867/node
at exports.resolve (internal/loader/ModuleRequest.js:126:13)
at Loader.resolve (internal/loader/Loader.js:48:40)
....
I'm using node version 8.9.1 and nyc version 13.0.1, running on Windows.
As the documentation states, .mjs support should be explicitly added: