3

Please does anybody know how i can address this issue ? I have my test:coverage defined as follows.

scripts{
 "test:coverage": "babel-node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha ./src/_utils/__tests__/*.js"
}

and when i run

npm run test:coverage

My mocha runs fine and everything else ok. But my istanbul coverage returns the message in the title at the end. Moreover , my coverage folder remains empty. After reading through online, i was convinced that i had to add .istanbul.yml file . I then proceed and add it below

verbose: false
instrumentation:
    root: ./node_modules/.bin/istanbul
    default-excludes: true
    excludes: []
    embed-source: false
    variable: __coverage__
    compact: true
    preserve-comments: false
    complete-copy: false
    save-baseline: false
    baseline-file: ./coverage/coverage-baseline.json
reporting:
    print: summary
    reports:
        - lcov
    dir: ./coverage
    watermarks:
        statements: [50, 80]
        lines: [50, 80]
        functions: [50, 80]
        branches: [50, 80]
hooks:
    hook-run-in-context: false
    post-require-hook: null

After i run my test:coverage again, the previous istanbul error dispappear. However, The no coverage message in the title still remains and more coverage folder still remains empty. Please where do i go wrong ? Any help would be appreciated.

Nuru Salihu
  • 4,756
  • 17
  • 65
  • 116

4 Answers4

8

Please if you encounter similar problem, know that the issue is with the istanbul itself. You need to install babel-istanbul not istanbul . My coverage:text is now like below.

 "test:coverage": "babel-node ./node_modules/.bin/babel-istanbul cover ./node_modules/.bin/_mocha ./src/**/__tests__/*.js",

Also its important to remember and get rid of the .istanbul.yml file . Instead change your src to the babel-istanbul . I removed my .istanbul.yml file and install babel-istanbul . Its working fine.

Nuru Salihu
  • 4,756
  • 17
  • 65
  • 116
5

Note: by default istanbul exclude some folders like test, tests and node_modules. If you have your scripts on a folder with that name, you should use --no-default-excludes, -i include-pattern and -x exclude-pattern to manage the folder you want to include or exclude.

example:

istanbul cover --no-default-excludes --report=text -x '**/node_modules/**' _mocha test/*

AmauryMejia
  • 51
  • 1
  • 4
1

this works for me with istanbul 1.0.0-alpha.2

babel-node ./node_modules/istanbul/lib/cli.js --include-all-sources cover ./node_modules/.bin/_mocha -- ./tests/ -R spec --recursive

found here: Running Mocha + Istanbul + Babel

Community
  • 1
  • 1
0

I'd faced similar issue as yours, but It worked when I switched to istanbul@.0.0-alpha.1 as per comment on their repo

istanbul cover --include-all-sources --report lcov -- _mocha test/**/*.test.js -R spec --timeout=60000 --compilers js:babel-core/register
Sridhar
  • 11,466
  • 5
  • 39
  • 43