cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.66k stars 3.16k forks source link

Not able to generate code coverage report on running vue 3 (typescript) application on a headless mode #29276

Open elangoRamar opened 5 months ago

elangoRamar commented 5 months ago

Current behavior

I am trying to generate the cypress code coverage report when i run the tests on a headless mode. But it's not generating the report.

And it's creating the report on interactive mode(cypress open -e2e).

Vue project dependency version: "vue": "^3.4.21", "vite": "^5.2.7",

And i am using "nyc": "^15.1.0" and "vite-plugin-istanbul": "^6.0.0" to generate the report.

Even i tried adding "@istanbuljs/nyc-config-typescript": "^1.0.2" and .nycrc configuration also not working.

Desired behavior

No response

Test code to reproduce

vite.config.ts

export default defineConfig({
  plugins: [
    vue(),
    vuetify({ autoImport: true }),
    istanbul({
      cypress: true,
      include: ['src/*'],
      exclude: ['node_modules'],
      extension: ['.js', '.ts', '.vue'],
      requireEnv: false
    })
  ],
  build: {
    sourcemap: true,
  }
});

cypress.config.js

import coverageTask from "@cypress/code-coverage/task";

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      coverageTask(on, config)
      return config;
    }
  }
});

cypress/support/e2e.ts import '@cypress/code-coverage/support'

command: cypress run --e2e

Cypress Version

13.7.2

Node version

20.12.0

Operating System

macOs 14

Debug Logs

getting below message,

Cannot find coverage file /Users/<user>/Documents/<project>/.nyc_output/out.json
Skipping coverage report

Other

No response

jennifer-shehane commented 4 months ago

I know there’s some comments in this thread about getting code coverage setup for ct testing, some of it may help you with a workaround. https://github.com/cypress-io/code-coverage/issues/596