Search code examples
vue.jscode-coveragecypressinstrumentationnyc

Cypress code coverage with nyc "all" option does not report source code as "uncovered"


My code coverage report shows 100% covered source code. However, I would expect less because there is only one test file (FooPage.spec.js) covering one (FooPage.vue) of two components. The second component (BarPage.spec.js) is shown in the report but not considered in the coverage metrics. I would have expected to see BarPage.ts reported as red with 0/4 statements covered (instead of 0/0).

unexpected code coverage

I guess, the instrumentation with nyc does not work as expected with the all option.

See https://github.com/toaditoad/code-coverage-mwe for a reproducible example.

See https://github.com/istanbuljs/nyc/issues/1415 with same question as well.


Solution

  • See Readme of my updated working example for a (not so nice) workaround to add all source files as additional entries in Cypress' webpack preprocessor: https://github.com/toaditoad/code-coverage-mwe

    This only works for Cypress 6.x but raised as request for Cypress 7.x which does not support the webpack preprocessor: https://github.com/cypress-io/cypress/issues/17230