xploreraj
xploreraj

Reputation: 4362

Unable to use nyc/istanbul for code coverage

I am using nightwatch for selenium based tests, but when I use nyc nightwatch, it only reports the test code and their 100% coverage. This is my primary blocker right now. How do I get the coverage? Basically, I want to get this as a report in Jenkins CI ultimately.

Additionally, I thought to test with my UTs as well for which I am using jest. Normally, "test": "jest --coverage" will list the coverage properly with all the tested code. So when I give nyc npm run test it gives me same coverage, which is good. But the moment I run with only nyc jest, it returns 100% coverage for jest.config.js!!

I don't have mocha or grunt etc.

Upvotes: 2

Views: 3506

Answers (1)

Drazisil
Drazisil

Reputation: 3343

Since jest uses nyc under the hood, there is no reason to use them together. You can call jest with the --coverage flag and tell it which reports to use in your config, as defined in the config:

  "jest": {
    "collectCoverage": true,
    "collectCoverageFrom": [
      "**/*.{js,jsx}",
      "!**/node_modules/**",
      "!**/vendor/**"
    ],
    "coverageReporters": [
      "text",
      "cobertura"
    ],
    "reporters": [
      "default",
      "jest-junit"
    ]
  }

https://jestjs.io/docs/en/configuration#coveragereporters-arraystring

Upvotes: 1

Related Questions