Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors even though test passes #53

Closed
ilanbiala opened this issue Apr 9, 2014 · 11 comments
Closed

Errors even though test passes #53

ilanbiala opened this issue Apr 9, 2014 · 11 comments

Comments

@ilanbiala
Copy link
Contributor

I get an error after all my tests pass.

I'm using Mocha and Istanbul.

[error] "2014-04-09T02:14:05.808Z"  'error from lcovParse: ' 'Failed to parse string'
[error] "2014-04-09T02:14:05.810Z"  'input: ' ''
[error] "2014-04-09T02:14:05.811Z"  'error from convertLcovToCoveralls'
node_modules/coveralls/bin/coveralls.js:18
        throw err;
              ^
Failed to parse string
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

This is my test statement by the way:

NODE_ENV=test istanbul cover mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

Any thoughts?

@cainus
Copy link
Collaborator

cainus commented Apr 11, 2014

It's probably easy to just follow the istanbul example in the README, or steal an example from one of my Makefiles: https://github.com/cainus/urlgrey/blob/master/Makefile#L36 . I'm going to guess that the issue is that you're running mocha rather than _mocha, but that's just a guess ( ie http://stackoverflow.com/questions/16633246/code-coverage-with-mocha ).

@ilanbiala
Copy link
Contributor Author

Yea I just tried that, it works now. What's the difference?

@ShashankaNataraj
Copy link

ShashankaNataraj commented Jul 18, 2016

@ilanbiala @cainus Im getting this exact same error right now..

This is what I have in my package.json:

"scripts": {
    "start": "node index.js",
    "test": "mocha",
    "coverage": "istanbul cover _mocha -- -R spec | coveralls"
  },

This is a nodejs project and Im using _mocha as can be seen above...

@kristianmandrup
Copy link

Please make it more clear, regarding the mocha vs _mocha thanks!

istanbuljs/nyc#433

@kristianmandrup
Copy link

What does this mean!?

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/kristianmandrup/repos/node-libs/code-operator/npm-debug.log
[error] "2016-11-01T20:27:26.209Z"  'error from lcovParse: ' 'Failed to parse string'
[error] "2016-11-01T20:27:26.213Z"  'input: ' '\n> code-operator-js@1.0.0 coverage /Users/kristianmandrup/repos/node-libs/code-operator\n> cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text --cache mocha src/**/*.test.js\n\n\n\n  Operator: code\n    an instance\n      1) have a name\n\n\n  0 passing (11ms)\n  1 failing\n\n  1) Operator: code an instance have a name:\n     AssertionError: expected { opts: \'kris\' } to deeply equal true\n      at Context.__dirname.that.should (src/operator/code.test.js:9:23)\n\n\n\n----------|----------|----------|----------|----------|----------------|\nFile      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |\n----------|----------|----------|----------|----------|----------------|\nAll files |    66.67 |        0 |    66.67 |    66.67 |                |\n code.js  |    66.67 |        0 |    66.67 |    66.67 |             11 |\n----------|----------|----------|----------|----------|----------------|\n'
[error] "2016-11-01T20:27:26.214Z"  'error from convertLcovToCoveralls'

/Users/kristianmandrup/repos/node-libs/code-operator/node_modules/coveralls/bin/coveralls.js:18
        throw err;
        ^
Failed to parse string

Running npm run coveralls

    "coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text --cache mocha src/**/*.test.js",
    "coveralls": "npm run coverage | coveralls",

Please advice! Thanks :)

@kristianmandrup
Copy link

Now trying istanbul cover _mocha src -- -R spec | coveralls

/Users/kristianmandrup/repos/node-libs/code-operator/src/operator/code.js:15
export default (opts) => {
^^^^^^
SyntaxError: Unexpected token export

So how do I get my babel/webpack into the mix!?

@rockchalkwushock
Copy link

rockchalkwushock commented Dec 27, 2016

@kristianmandrup don't know if you are still having issues; but if you set up your .nycrc & .babelrc as follows and include the babel-register & babel-plugin-istanbul package you should be fine with using ES6. Istanbul has a brief tutorial on how to use nyc with es2015+ that can be found here:

Using Istanbul with ES2015+

.nycrc

{
  "reporter": [
    "lcov",
    "text-summary"
  ],
  "require": [
    "babel-register"
  ],
  "sourceMap": false,
  "instrument": false
}

.babelrc

{
  "presets": [
    "es2015",
    "stage-0"
  ],
  "env": {
    "test": {
      "plugins": [ "istanbul" ]
    }
  }
}

Just a friendly FYI too I found out my problem was I was running my testing script in NODE_ENV=development and the environment in the .babelrc was set for test. Apparently it does matter that it is test because switching the environment to development in the .babelrc still gave me problems, but as soon as the environment was changed to test across the board all was good in testing hood!

@kristianmandrup
Copy link

Thanks! I really wish utils such as these had brief configuration guides for common/modern combinations such as these :)

@immnk
Copy link

immnk commented Jan 19, 2019

If someone is having this issue in 2019, please read this blog: https://medium.com/@asciidev/when-coveralls-made-me-pull-a-hair-a41118bd8a73

Basically you need to run nyc with NODE_ENV=test to pass coverage report from nyc to coveralls

nyc report --reporter=text-lcov | coveralls

@briantical
Copy link

I am using CircleCi and Jest for testing.
This is how I solved the error from my project

In package.json

"test": "jest --coverage",
"coverage": "coveralls < coverage/lcov.info"

Removing the | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage from the test command seemed to do the trick.

@zdrawku
Copy link

zdrawku commented Jan 7, 2021

I've faced a similar problem, hope this post might help you a little bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants