code-coverage icon indicating copy to clipboard operation
code-coverage copied to clipboard

Coverage report appears before end of Cypress output?

Open bgoosmanviz opened this issue 4 years ago • 1 comments

Logs and screenshots Here is what I mean. "removeNodeById" is the last test in my single test file. As you can see, Cypress is correctly using the coverage:report script I defined in package.json. However, it is printing the coverage in the middle of my test results, which isn't blocking but is mildly annoying.

  ...
    1) addNode adds a node
...

> [email protected] coverage:report /Users/admin/.../api
> nyc report

-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |     100 |      100 |     100 |     100 |                   
 addNodes.ts       |     100 |      100 |     100 |     100 |                   
...                 
-------------------|---------|----------|---------|---------|-------------------
    ✓ removeNodeById removes a node (115ms)


  4 passing (12s)
  1 failing
...

Versions

  • What is this plugin's version? ^3.9.6
  • What is Cypress version? ^7.5.0
  • What is your operating system? MacOS
  • What is the shell? zsh
  • What is the Node version? v12.13.0
  • What is the NPM version? 6.12.0
  • How do you instrument your application? babel-loader w/ istanbul and @babel/preset-typescript
  • When running tests, if you open the web application in regular browser, and open DevTools, do you see window.__coverage__ object? Yup, works great.
  • Is there .nyc_output folder? Is there .nyc_output/out.json file. Coverage is working.
  • Do you have any custom NYC settings in package.json (nyc object) or in other NYC config files
  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "extension": [
      ".ts"
    ],
    "include": [
      "src/**/*.ts"
    ],
    "exclude": [
      "cypress/",
      "dist/",
      "src/**/*.d.ts",
      "src/**/*.spec.ts"
    ],
    "excludeAfterRemap": false,
    "checkCoverage": true,
    "all": true,
    "branches": 100,
    "functions": 100,
    "lines": 100,
    "statements": 100,
    "skipEmpty": true,
    "reporter": [
      "lcov",
      "text"
    ]
  },
  • Do you run Cypress tests in a Docker container? Nope

Describe the bug I'm confused why the coverage is printing before the outcome of my last test.

Link to the repo Sorry don't have this.

bgoosmanviz avatar Jun 14 '21 01:06 bgoosmanviz

I was having this issue too. My fix was removing text-summary from the reporter block in the .nyrc config, and then adding it to my test command in package.json. The lcov and json reports are still built too.

// .nycrc
{
  "all": true,
  "extends": "@istanbuljs/nyc-config-typescript",
  "reporter": ["lcov", "json"],
  "include": "src/**",
  "exclude": [
    "**/__tests__/**",
    "**/.{eslint,mocha}rc.{js,cjs}",
    "**/{ava,babel,nyc}.config.{js,cjs,mjs}"
 ]
}
// package.json
{
  "name": "myProject",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "node generate-api.cjs && vite",
    "build": "tsc && vite build",
    "preview": "vite preview",
    "test": "npx cypress run --component && npx nyc report --reporter=text-summary"
  }
  // ...rest of the package.json file
}

mitchwd avatar Jun 18 '23 06:06 mitchwd