Reputation: 3655
My goal is to be able to write src and tests files in es6, all in the same directory (I want my test files to be side-by-side with my source files), and get coverage report with the original files.
The best I can come up with at this point is to have my test files included in the coverage report with the following command:
./node_modules/.bin/babel-node node_modules/.bin/babel-istanbul \
cover \
node_modules/.bin/_mocha -- 'src/**/*.spec.*.js'
I did try using the cover -x 'src/**/*.spec.*.js'
, it also excludes the files from transpiling and mocha
then fails to run the tests. For the life of me, I cannot figure out how to do the equivalent of something like this:
./node_modules/.bin/babel-node node_modules/.bin/babel-istanbul \
cover -x 'src/**/*.spec.*.js' \
node_modules/.bin/_mocha -- --require babel-core/register 'src/**/*.spec.*.js'
this will run all my tests fine but has the negative effect of giving me:
No coverage information was collected, exit without writing coverage information
So I am not too far from what I want, I'm think I'm just missing that last piece there and if somebody can help here, it would be really appreciated.
Regards, D.
Upvotes: 4
Views: 1375
Reputation: 3655
For anyone finding this much later, the stack with mocha
, @babel
and nyc
is much much much much (did I say much?) easier to configure. No more need of that babel-node
.
package.json
:
{
...
"scripts": {
"coveralls": "cat reports/coverage/lcov/info | coveralls", // <-- Used on CI
"coverage": "nyc --report-dir=reports/coverage npm test",
"test": "mocha \"src/**/*.test.js?(x)\""
},
"mocha": {
"require": [
"@babel/register",
...
]
},
...
}
and here's an example of my .nycrc
:
{
"all": true,
"cache": false,
"temp-dir": "./reports/nyc_output",
"check-coverage": false,
"require": [
"@babel/register"
],
"exclude": [
"dist/",
"reports/",
"src/**/*.test.js",
"src/**/*.test.jsx"
],
"extension": [
".js",
".jsx"
],
"reporter": [
"cobertura",
"lcov",
"html"
],
"watermarks": {
"statements": [50, 80],
"lines": [50, 80],
"functions": [50, 80],
"branches": [50, 80]
}
}
Upvotes: 0
Reputation: 681
Never got the -x
option to do what I wanted. If you don't mind using an .istanbul.yml
file this worked for me to get side-by-side tests excluded from coverage reports...
npm run cover
command:
babel-node node_modules/.bin/babel-istanbul cover _mocha -- --opts mocha.opts
project_dir/mocha.opts
file:
src/**/*.test.js
--compilers js:babel-register
--require babel-polyfill
project_dir/.istanbul.yml
file:
instrumentation:
root: src
include-all-sources: true
verbose: true
excludes: ["*.test.js"]
reporting:
dir: "coverage"
Upvotes: 5