Reputation: 145
I'm performing mocha tests on my React components that I wrote using ES6 syntax. I'm using Istanbul to do code coverage tests. When i set my NODE_ENV
to 'test`, I get the following output:
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
As can be seen, it says unknown for everything. When I remove the NODE_ENV
variable, it works fine. What can I do to run this test in the above environment?
Upvotes: 3
Views: 1454
Reputation: 1255
Use cross-env
(https://www.npmjs.com/package/cross-env)
In package.json
:
"test": "cross-env NODE_ENV=test nyc mocha --exit && npm run coverage"
Upvotes: 0
Reputation:
I have been trying the last two days to set up a similar environment using babel, nyc and react and faced similar problems. How are you setting the NODE_ENV? Are you on Windows?
This is what I had in my package.json:
"test:c": "set NODE_ENV=test && npm run coverage"
When this is executed, windows actually sets the NODE_ENV as "test " not as "test". Notice the trailing whitespace.
I fixed this by removing the space from the script :
"test:c": "set NODE_ENV=test&& npm run coverage"
Upvotes: 3