Skip to content

Cypress Coverage Report Not Generating Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Cypress Coverage Report Not Generating Fix. We cover key concepts, practical examples, and best practices.

Your Cypress tests run but no coverage report is generated — the coverage counters stay at zero or the report is empty.

The Problem

# WRONG — no coverage plugin configured
npx cypress run

Tests pass but no coverage/ directory is created. Cypress doesn't collect code coverage out of the box.

Step-by-Step Fix

1. Install code coverage plugin

npm install -D @cypress/code-coverage

2. Configure in cypress config

// RIGHT — cypress.config.js
const { defineConfig } = require('cypress');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      require('@cypress/code-coverage/task')(on, config);
      return config;
    },
  },
});

3. Add support file import

// RIGHT — cypress/support/e2e.js
import '@cypress/code-coverage/support';

4. Configure application for coverage

// RIGHT — instrument the app (using Vite)
// vite.config.js
export default {
  plugins: [
    // For production builds:
    process.env.CYPRESS && require('"@cypress"/code-coverage/vite')(),
  ].filter(Boolean),
};

5. Run and view coverage

# Run tests
npx cypress run

# Coverage report in ./coverage/
open coverage/lcov-report/index.html

Expected output:

  ✓ login flow
  ✓ dashboard loads

| File                  | % Stmts | % Branch | % Funcs | % Lines |
|-----------------------|---------|----------|---------|---------|
| All files             |      85 |       78 |      82 |      84 |
| src/components/Login  |      90 |       85 |      88 |      89 |

Prevention Tips

  • Install @<a href="/testing-qa/cypress/">cypress</a>/code-coverage package
  • Configure setupNodeEvents in Cypress config
  • Import plugin in support file
  • Instrument the application code
  • Run coverage in CI with npx <a href="/testing-qa/cypress/">cypress</a> run

Common Mistakes with coverage report

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world CYPRESS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Does Cypress coverage work with TypeScript?

Yes. Use the Istanbul instrumenter transformer (babel-plugin-istanbul or vite-plugin-istanbul) to instrument TypeScript source files. The coverage report includes TS files.

Can I exclude files from Cypress coverage?

Yes. Configure exclude in Istanbul options: nyc config in package.json or .nycrc file with "exclude": ["src/**/*.test.*", "src/config/**"].

What's the difference between unit test coverage and E2E coverage?

Unit tests cover individual functions in isolation. E2E tests (Cypress) cover the full application stack. E2E coverage shows which code paths are exercised by real user interactions.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro