https://cypress.io logo
coverageReport fails when performing e2e tests
# i-need-help
n
Hi everyone. I'm developing component and e2e tests for a React application. Component tests run fine and the coverage is generated. When it comes to the e2e part, the tests pass, but
cy.task('coverageReport')
fails with the following error:
The argument 'path' must be a string or Uint8Array without null bytes. Received '/Users/redacted/Documents/projects/redacted/backoffice-fe/cypress-coverage/lcov-report/backoffice-fe/\x00commonjsHelpers.js.html'
I don't know what that file is and why the name starts with a null byte. This happens both on my machine and in CI. I cannot find anything on Google, I would be very thankful if anyone had a clue. Thanks
I forgot to attach my cypress.config.ts:
Copy code
js
export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      require("@cypress/code-coverage/task")(on, config);
      return config;
    },
    experimentalStudio: true,
    experimentalWebKitSupport: true,
    specPattern: "cypress/e2e/**/*.cy.ts",
    baseUrl: "http://localhost:3000",
  },

  component: {
    setupNodeEvents(on, config) {
      require("@cypress/code-coverage/task")(on, config);
      return config;
    },
    devServer: {
      framework: "react",
      bundler: "vite",
    },
    specPattern: "src/**/*.cy.{ts,tsx}",
  },
});
My vite config file is the following:
Copy code
js
export default defineConfig({
  plugins: [react({ babel: { plugins: ["istanbul"] } }), tsconfigPaths()],
  server: { port: 3000, proxy: { "/api": "http://localhost:8080" } },
  test: {
    globals: true,
    environment: "jsdom",
    setupFiles: "./src/setupTests.ts",
    coverage: {
      reportsDirectory: "vitest-coverage",
      reporter: ["text", "lcov", "json"],
      exclude: ["node_modules", "src/setupTests.ts"],
    },
  },
  build: { outDir: "./build" },
  define: {
    APP_VERSION: JSON.stringify(process.env.npm_package_version),
  },
});
Also, in
package.json
I have configured
nyc
to output the report to a folder named
cypress-coverage
so it doesn't override the output of my vitest test. The reports are merged later in the pipeline