code-coverage: Unit test code coverage is not exported

Hi everyone, I’m trying to implement code coverage in my project react CRA + Typescript in e2e and unit tests and what is happening, is that when I run e2e tests, everything works fine but when I run unit testing, the files from the coverage folder and the .nyc_output folder are not being generated

I’m follow this tutorial: https://docs.cypress.io/guides/tooling/code-coverage.html#Introduction

package.json

{
  ...
  "devDependencies": {
    ...
    "@cypress/code-coverage": "^3.8.5",
    "babel-eslint": "^10.1.0",
    "babel-plugin-istanbul": "^6.0.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "cypress": "^6.1.0",
    "istanbul-lib-coverage": "^3.0.0",
    "nyc": "^15.1.0"
  },
  ...
}

.babelrc

{
    "presets": ["react-app", "@babel/preset-react"],
    "env": {
      "development": {
        "plugins": ["istanbul"]
      }
    },
    "plugins": ["transform-class-properties"]
}

cypress/plugins/index.ts

/// <reference types="cypress" />
const browserify = require("@cypress/browserify-preprocessor");

module.exports = (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => {
	require("@cypress/code-coverage/task")(on, config);

	const options = browserify.defaultOptions;
	options.browserifyOptions.transform[1][1].babelrc = true;
	on("file:preprocessor", browserify({ ...options, typescript: require.resolve("typescript") }));

	return config;
};

cypress/support/index.ts

import "@cypress/code-coverage/support";
import "./commands";

To start testing, fisrt i start application with yarn start and after i run yarn cypress run --spec './cypress/integration/units/**/*'

I’m testing on my windows 10 computer with powershell but I need this to put in docker container to run on Drone CI. I’ll run the unit tests on each PR and when I open a PR for master/main I’ll run the unit tests and e2e tests

The console log shows:

Cannot find coverage file C:\Users\Paulo\Desktop\teste-eject\.nyc_output\out.json
Skipping coverage report

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 7
  • Comments: 17 (4 by maintainers)

Most upvoted comments

@bahmutov Can u please provide a solution to this issue? Of all the work we did to replace testing framework from Jest and Selenium to Cypress last year, this is the only limitation we are stuck now. Thanks.

const browserify = require('@cypress/browserify-preprocessor')
const options = browserify.defaultOptions
options.browserifyOptions.transform[1][1].babelrc = true
// instrumentation is not working if we set
options.typescript = require.resolve('typescript')
module.exports = browserify(options)

@bahmutov have a look at this repo SVGPathCommander direct link to workflow run the exact same issue

Cannot find coverage file /home/runner/work/svg-path-commander/svg-path-commander/.nyc_output/out.json
Skipping coverage report

I’m using esbuild with istanbul instrumenter, working flawless on my machine, fails on Github.

Appreciate any input from anyone.

I don’t know if this is the case for all the situations reported here, but I hit this error message this past week and it was caused by the application code not being instrumented for code coverage when running in the CI process. It worked fine locally, as it was going through a different code pathway and it was instrumented in that case.