Open tomasruizr opened 5 years ago
it work well when I remove
"env": { "test": { "plugins": ["istanbul"] } },
and 'NODE_ENV=test '
Thanks for the quick response... Tried what you proposed but no luck yet. Still empty reports
Thanks for the quick response... Tried what you proposed but no luck yet. Still empty reports
So sorry that couldn't help you. In my project , if use nyc, no need use webpack.
"nyc": {
"reporter": [
"text-summary",
"html"
],
"require": [
"@babel/register"
],
"extension": [
".js"
],
"cache": true,
"temp-dir": "./dist/tests/.nyc-temp",
"report-dir": "./dist/tests/nyc"
}
2.modify package.json , add "test": "nyc mocha --ui bdd ./tests/field.js"
in scripts prop;
run test
Great THANKS! We are getting somewhere... With the config you propose now its instrumenting the js files... YAY!!!!
But the thing is I need to instrument Vue files too. So I went Back to my original configuration and remove the module.rules -> include
in the istanbul loader configuration for the webpack.config.test.js file and got the same result, but still no Vue files instrumentation.
The weird thing is that the same config prior babel update worked as expected.
Any suggestions?
@tomasruizr my config
package.json
{
"scripts" : {
"test:nyc" : "cross-env NODE_ENV=test nyc mocha --ui bdd ./tests/**.js"
},
"dependencies" : {
"@babel/register" : "^7.0.0",
"mockjs" : "^1.0.1-beta3",
"regenerator-runtime": "^0.13.1",
"vue" : "^2.5.21"
},
"devDependencies": {
"@babel/core" : "^7.2.2",
"@babel/preset-env" : "^7.2.3",
"babel-loader" : "^8.0.5",
"babel-plugin-istanbul" : "^5.1.0",
"babel-register" : "^6.26.0",
"chai" : "^4.2.0",
"cross-env" : "^5.2.0",
"eslint" : "^5.12.0",
"istanbul" : "^0.4.5",
"istanbul-instrumenter-loader": "^3.0.1",
"jsdoc" : "^3.5.5",
"jsdom" : "^13.1.0",
"mocha" : "^4.0.1",
"nyc" : "^13.1.0",
"webpack" : "^4.28.4"
}
}
.babelrc
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
],
"env": {
"test": {
"plugins": [
"istanbul"
]
}
}
}
I found that the problem is in using webpack's module aliases. When I changed it to babel module alias plugin, it worked
Hey @gugu Great to hear that!, I'll be looking into it. Thanks!
Hey guy's, I think the problem is on a other site.
Set in your nyc-config in the package.json
the cache-attribute of false.
"nyc": {
"cache": false
},
or use the --cache false
flag
@tomasruizr still bumping into issues? if you can provide a minimal reproduction it might help folks dig into the issue a bit more -- I haven't done played much with Vue, so don't quite know where to start.
Thanks for the interest @bcoe , I've been a bit over the top with the deadlines of the project so I temporarily downgrade the babel version and have been snoozing the upgrade since. I Will find the time to attempt the upgrade between this week and the next. I'll let you know how it goes. Thanks again.
After fighting with this for a while I finally found what was causing it for me, which looks like it might be the same issue you are having.
All of the documentation and examples show running nyc something like this:
cross-env NODE_ENV=test nyc mocha
With configuration in your .babelrc
that includes:
env: {
test: {
plugins: [ 'istanbul' ],
}
}
Which I see is what you are doing, and this all works great for most people. However, when determining which env
sections to use from your .babelrc
, NODE_ENV
is the fourth thing that babel checks. When determining the env
to use, babel looks at:
--env-name=<name>
envName: "<name>"
process.env.BABEL_ENV
process.env.NODE_ENV
So basically the recommended configuration will work just fine if your environment doesn't contain $BABEL_ENV
, but if it does (and it's set to anything other than test
) then that configuration will just report Unknown
for everything, because nothing actually got instrumented.
So, in my case I was having this problem:
$ nyc mocha
...
=============================== Coverage summary ===============================
Statements : Unknown% ( 0/0 )
Branches : Unknown% ( 0/0 )
Functions : Unknown% ( 0/0 )
Lines : Unknown% ( 0/0 )
================================================================================
And it was all caused by this:
$ echo $NODE_ENV
test
$ echo $BABEL_ENV
development
Just making sure that BABEL_ENV was either also set to the right value, or else cleared entirely fixed the problem for me:
$ BABEL_ENV= nyc mocha
...
=============================== Coverage summary ===============================
Statements : 41.62% ( 2442/5867 )
Branches : 30.84% ( 847/2746 )
Functions : 35% ( 531/1517 )
Lines : 42.96% ( 2275/5296 )
================================================================================
I'm using babel.config.js
rather than .babelrc
, which gives you a lot more flexibility than JSON does. So what I ended up doing to fix it was just not using the env : { test : { plugins : [ 'istanbul' ] } }
and instead I added something like this to my configuration function:
const { NODE_ENV, BABEL_ENV, NYC_ROOT_ID } = process.env;
if ( NODE_ENV && BABEL_ENV && NODE_ENV !== BABEL_ENV ) {
console.warn( `WARNING: Both BABEL_ENV and NODE_ENV are set in` );
console.warn( `WARNING: the environment, but with different values.` );
console.warn( `WARNING: BABEL_ENV = ${BABEL_ENV}` );
console.warn( `WARNING: NODE_ENV = ${NODE_ENV}` );
}
const isCoverage = ( NODE_ENV === 'test' || BABEL_ENV === 'test' || NYC_ROOT_ID );
const plugins = [
isCoverage && 'babel-plugin-instanbul',
// ... all my other plugins here
].filter( Boolean );
return { presets, plugins };
Have you determined what was setting BABEL_ENV and why? Maybe "mode": "development"
in your webpack config?
It was set in the environment where my app was running. It wasn't that something unexpected was setting it, basically my .env
file included both:
NODE_ENV=development
BABEL_ENV=development
but then when running tests, only NODE_ENV
was getting set to test
. Just taking BABEL_ENV
out of the environment fixed the problem,
In my case, the reason was that NODE_ENV
wasn't set to the env
stage name that was configured with babel-plugin-istanbul
in babel.config.js
.
Hello, Im running into a problem of empty reports after upgrading babel 7, It was ok before.
What am I missing? Thanks In advance.
here's my config
command:
NODE_ENV=test nyc --reporter=lcov --reporter=text mocha-webpack --reporter spec --webpack-config webpack.config.test.js \"src/**/*.test.js\" --interactive false
babel.rc
webpack.config.test.js
Dev Dependencies