galkin
galkin

Reputation: 5519

How set up test code coverage with different test levels?

I'm using nyc for generating Code coverage reports. I use different levels for my tests. How I can merge reports from different levels?

There is my part of my package.json

"scripts": {
  "test": "npm run test:unit && npm run test:component",
  "test:component": "nyc mocha ./test/component",
  "test:unit": "nyc mocha ./test/unit"
},
"nyc":     {
  "extension": [
    ".ts"
  ],
  "cache": true,
  "reporter": [
    "lcov",
    "text-summary"
  ]
}

Upvotes: 1

Views: 88

Answers (1)

Ivan Drinchev
Ivan Drinchev

Reputation: 19581

You can use nyc and mocha in a sequence to achieve this effect.

With npm scripts this will look like :

{
    "scripts": {
        "coverage" : "nyc npm run test",
        "test": "npm run test:unit && npm run test:component",
        "test:component": "mocha ./test/component",
        "test:unit": "mocha ./test/unit"
    },
    "nyc": { ... }
}

The main idea, behind nyc is that it takes all the source files defined in your configuration and instruments them.

Then it runs the command after the instrumentation with modified require, so every command that you run from inside nyc will have the instrumented files as it's source.

Upvotes: 1

Related Questions