Coverage report always empty when nyc_output has coverage results

See original GitHub issue

Link to bug demonstration repository

I tried setting up code coverage in an Angular 8 project using Cypress and istanbul nyc.

I managed to get the code instrumented (the global variable __coverage__ is properly set) :

enter image description here

and the coverage file generated in .nyc_output after running cypress:open

enter image description here

But the generated coverage report is empty:

$ cat coverage/coverage-final.json
{}

Same result when I execute the command:

$ npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=text
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|

Here is my package.json devDependencies:

"devDependencies": {
  "@angular-devkit/build-angular": "^0.803.3",
  "@angular-devkit/build-optimizer": "^0.803.3",
  "@angular/cli": "^8.3.3",
  "@angular/compiler-cli": "8.2.5",
  "@angular/language-service": "8.2.5",
  "@briebug/cypress-schematic": "^2.0.0",
  "@cypress/code-coverage": "^1.10.1",
  "@cypress/webpack-preprocessor": "^4.1.0",
  "@istanbuljs/nyc-config-typescript": "^0.1.3",
  "@types/jasmine": "^3.4.0",
  "@types/jasminewd2": "^2.0.6",
  "@types/node": "^12.7.4",
  "babel-plugin-istanbul": "^5.2.0",
  "codelyzer": "^5.1.0",
  "cypress": "^3.4.1",
  "istanbul-instrumenter-loader": "^3.0.1",
  "istanbul-lib-coverage": "^2.0.5",
  "jasmine-core": "^3.4.0",
  "jasmine-spec-reporter": "4.2.1",
  "karma": "^4.3.0",
  "karma-chrome-launcher": "^3.1.0",
  "karma-cli": "^2.0.0",
  "karma-coverage-istanbul-reporter": "^2.1.0",
  "karma-jasmine": "^2.0.1",
  "karma-jasmine-html-reporter": "^1.4.2",
  "mochawesome": "^4.1.0",
  "ngx-build-plus": "^8.1.4",
  "nyc": "^14.1.1",
  "protractor": "^5.4.2",
  "protractor-html-reporter-2": "^1.0.4",
  "protractor-http-client": "^1.0.4",
  "source-map-support": "^0.5.13",
  "ts-node": "^8.3.0",
  "tslib": "^1.10.0",
  "tslint": "^5.19.0",
  "typescript": "3.5.3"
}

And my .nycrc.json:

{
    "cache": false,
    "extension": [
      ".ts",
      ".tsx"
    ],
    "exclude": [
      "**/*.d.ts",
      "coverage/**",
      "packages/*/test/**",
      "test/**",
      "test{,-*}.ts",
      "**/*{.,-}{test,spec}.ts",
      "**/__tests__/**",
      "**/node_modules/**"
    ],
    "all": true,
    "check-coverage": true,
    "require": [
      "ts-node/register"
    ],
    "temp-directory": ".nyc_output",
    "sourceMap": false,
    "instrument": false,
    "include": ["src/**/*.ts", "src/**/*.tsx"]
}

Expected Behavior

Get non empty coverage report

Observed Behavior

Coverage report is empty

Troubleshooting steps

  • [X ] still occurring when I put cache: false in my nyc config

Environment Information

$ npx envinfo@latest --preset nyc
npx: installed 1 in 5.232s

  System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-4910MQ CPU @ 2.90GHz
    Memory: 16.55 GB / 31.88 GB
  Binaries:
    Node: 10.16.3 - D:\software\nodejs\node.EXE
    npm: 6.9.0 - D:\software\nodejs\npm.CMD
  npmPackages:
    babel-plugin-istanbul: ^5.2.0 => 5.2.0
    istanbul-instrumenter-loader: ^3.0.1 => 3.0.1
    istanbul-lib-coverage: ^2.0.5 => 2.0.5
    karma-coverage-istanbul-reporter: ^2.1.0 => 2.1.0
    nyc: ^14.1.1 => 14.1.1
    source-map-support: ^0.5.13 => 0.5.13
    ts-node: ^8.3.0 => 8.3.0
    typescript: 3.5.3 => 3.5.3
    typescript-example:  1.0.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
roublescommented, Sep 17, 2021

This is what worked for me:

npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=text --exclude-after-remap false

3reactions
jidmacommented, Sep 10, 2019

After some digging I found that when the property "excludeAfterRemap": true (seems to be the default value) all the files are excluded here :

nyc/index.js:

390:    if (this.config.excludeAfterRemap) {
391:      map.filter(filename => this.exclude.shouldInstrument(filename))
392:    }

Even though this.exclude.shouldInstrument(filename)) returns true for my file.

Chaning to this

nyc/index.js:

if (this.config.excludeAfterRemap) {
  map.filter(filename => { return this.exclude.shouldInstrument(filename) }) //added return statement
}

Fixed the problem:

$ npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=text
--------------------|----------|----------|----------|----------|-------------------|
File                |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files           |    43.59 |    14.81 |    42.86 |    41.89 |                   |
 login.component.ts |    37.93 |        8 |       50 |     37.5 |... 15,117,118,120 |
 login.module.ts    |      100 |      100 |      100 |      100 |                   |
 login.service.ts   |    52.94 |      100 |     37.5 |       50 |... 27,28,29,35,36 |
--------------------|----------|----------|----------|----------|-------------------|

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty istanbul (nyc) report while coverage files are filled ...
I expect nyc report --cwd . to show the coverage result, but the report is always empty. Neither files nor coverage results are...
Read more >
Code coverage with Siesta - Siesta API documentation
Code coverage provides information about what parts of your codebase are executed while running your test suite. Such code is called "covered" with...
Read more >
Karma Coverage Always Coming Empty - ADocLib
Reports. The coverage folder has results in several formats, and the coverage raw data is stored in.nyc_output folder. that should be there according...
Read more >
Code Coverage results empty (again) - Visual Studio Feedback
It now always says ' Empty results generated: No binaries were instrumented. Make sure the tests ran, required binaries were loaded, had matching...
Read more >
Xcode 9.3 Code Coverage | Apple Developer Forums
When I was using Xcode 9.2, the editor would correctly show code coverage. However, code coverage reports were always empty.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found