Cypress nyc code coverage is not instrumenting the code

1.9k Views Asked by At

I am trying to introduce e2e code coverage in my react app. I can see hash-file.json is getting created in .nyc_output

below are my package.json scripts

{
        "start": "npm run clean && cross-env NODE_ENV=test node ./tools/devServer.js",
        "e2e": "nyc cypress open",
}

enter image description here

its not updating .nyc_output/out.json

enter image description here

.babelrc

{
    "presets": [
        "@babel/preset-react"
    ],
    "env": {
        "test": {
          "plugins": [ "istanbul"], {
            "exclude": [
              "src/**/*.spec.js",
              "src/**/*.test.js",
              "e2e-coverage"
            ],
            "include":["src/"]
          }]
        }
      },
    "ignore": ["node_modules","build"]
}
  1. What are the above has-file.json, and why it gets created, if i followed correctly instead of this it should write the coverage in out.json ?

  2. I followed the document, but still it looks like there is some issue in instrumenting the code. (what could be the issue ?)

  3. In some of the examples i saw logs with isInteractive:true, what is this meant for and where is its configuration handler ?

  4. What could be the expected cause for it not getting instrumented enter image description here

enter image description here

Solution:-

I followed and included the instrumenting process as part of webpack build loader, and it's working fine. But still i am looking answers for by above points. I was expecting babel-istanbul-plugin will do it on the fly, no need to do with webpack.

https://webpack.js.org/loaders/istanbul-instrumenter-loader/

0

There are 0 best solutions below