Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk8 min

How to Get Complete Code Coverage With Cypress

Cypress coverage requires instrumented application code, plugin collection, and reports that match your chosen scope. Learn how to configure E2E, component, and backend coverage—and use the results without treating 100% as proof of test quality.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To get meaningful code coverage with Cypress, instrument the application code, collect the resulting counters during tests with @cypress/code-coverage, generate a report, and add tests for important uncovered behavior. Cypress does not instrument application code automatically. “Complete” should mean that your chosen code scope and critical behaviors are deliberately covered—not that every project must reach 100%.

Decide what “complete coverage” means for your project

Source-code coverage reports which instrumented statements, branches, functions, and lines ran during tests. It does not show whether a test’s assertions are correct or whether a test would catch a regression. A high percentage is useful only when the tests exercise behavior that matters and check its results.

Before configuring coverage, decide which code belongs in the report:

  • Frontend application code: the usual starting point for browser-based end-to-end tests.
  • Component-test code: application components exercised by Cypress component tests; this requires the component support file and component build pipeline to be configured too.
  • Backend code: server-side code must be instrumented and its coverage counters made available to the collector. Browser coverage alone does not measure it.
  • Test or other code: include only when you intentionally want to measure it. Exclude dependencies and test files from ordinary application coverage unless they are part of the scope you have chosen.

Keep the scope consistent when comparing reports. A report that adds backend or component-test coverage is not directly comparable to one that measures only frontend end-to-end runs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose instrumentation that fits your build

Cypress’s test runner collects coverage counters; it does not add them to your source. As Cypress’s documentation puts it, “Cypress does not instrument your code – you need to do it yourself.” Choose an instrumentation route that matches how your application is built, and verify that generated source maps let reports point back to original files.

Build workflow Instrumentation approach Important considerations
Separate instrumentation step Use NYC to instrument source into a separate directory. Cypress’s guide gives npx nyc instrument --compact=false src instrumented as an example. --compact=false makes generated output easier to inspect. Ensure the test server serves the instrumented build, not the original uninstrumented source.
Babel transpilation Configure babel-plugin-istanbul in the Cypress build environment. Scope Istanbul to Cypress runs where appropriate. Enabling it globally can duplicate instrumentation when Jest also instruments code; Cypress documents using a Cypress-specific Babel environment such as BABEL_ENV=cypress.
Vite Use vite-plugin-istanbul in the Vite configuration used for Cypress. Set appropriate include, exclude, and extension options. Vue single-file components may require .vue, and TypeScript sources may require .ts. A gated setup can use requireEnv: true and VITE_COVERAGE=true.

NYC and Babel/Istanbul instrument application code rather than third-party node_modules dependencies by default. Keep generated reports focused on code you own unless you have a specific reason to expand the scope.

Install and configure coverage collection

Install @cypress/code-coverage as a development dependency using your project’s package manager. The collector needs both a support-file import in the browser test context and a Node task registered through setupNodeEvents.

  1. Import the support module. Add import '@cypress/code-coverage/support' to the Cypress support file used by the tests you want covered.
  2. Register the task. In the relevant Cypress configuration file, register @cypress/code-coverage/task inside setupNodeEvents.
  3. Return the configuration. Return the resulting config from setupNodeEvents, including any environment or configuration changes made there.
  4. Run the app with instrumentation enabled. The browser needs to load the instrumented application so its coverage object is available for collection.
  5. Run Cypress and inspect the output. Confirm that raw coverage data is produced and that the report contains the intended original source files.

Configuration APIs can vary by Cypress and plugin version. The official @cypress/code-coverage repository’s v4 migration notes describe a change for Cypress v15.10 and later: older Cypress.env()-based examples should not be copied blindly. The migration example moves configuration from env to expose; check the installed plugin’s documentation and your Cypress version before adapting configuration.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure end-to-end and component tests separately

End-to-end tests

For end-to-end coverage, import the support module from the E2E support file and register the task in the E2E Node-event configuration. Make sure the application served to the browser is the instrumented version. If the report is empty, first check whether the loaded page exposes window.__coverage__.

Component tests

Component testing uses a separate support file and build path. Import the coverage support module from the component support file as well; an import in the E2E support file does not collect component-test coverage. Register the task for the component test configuration too, as applicable to your project’s Cypress configuration.

With Vite, configure the Istanbul plugin in the component dev server’s Vite setup. With Webpack, add Istanbul to the component-test transpilation or bundling rules. Coverage of unit-test spec files is another explicit setup: instrument those files and use the relevant shared Babel configuration. Do not assume that enabling application coverage automatically includes test files.

Add backend coverage when your goal includes server code

Frontend instrumentation cannot report which server-side branches ran. For a Node backend, start the server under NYC so it records counters, then expose its coverage object for the Cypress collector. Cypress’s guide describes Express and Hapi middleware approaches; another option is to expose a GET /__coverage__ endpoint.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Instrument the backend and start it in a way that preserves its coverage counters during the test run.
  2. Expose the backend coverage object through framework middleware or a coverage endpoint.
  3. Configure the coverage plugin to fetch the backend endpoint.
  4. Run the browser tests and confirm the report includes both the intended frontend and backend files.

The collector can merge the backend counters with frontend coverage. Protect any coverage endpoint so it is not exposed as an unnecessary public production interface; use a test-only route or equivalent environment-specific approach.

Generate and interpret a coverage report

The plugin stores raw coverage data under .nyc_output and can generate an HTML report that Cypress’s guide says is available at coverage/index.html. To print a terminal summary, run:

npx nyc report --reporter=text-summary

NYC supports other reporters as well. In CI, preserve the coverage directory as a build artifact so developers can inspect the HTML report after the run.

Use uncovered lines and branches to choose specific tests, prioritizing:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Business rules and important conditional branches.
  • Error handling, validation failures, and boundary cases.
  • Paths that could affect user data, security, money, or other consequential outcomes.
  • Code that has changed recently or has caused regressions.

Write assertions for expected behavior, not merely steps that cause code to execute. A test that visits a page can increase coverage without proving that the page behaves correctly.

How to work toward 100% without gaming the metric

There is no universal coverage percentage that defines completeness. A real-world 100% result may take multiple tests, and it still does not establish that assertions are adequate. Treat 100% as a possible scoped target, not proof of quality or a requirement for every project.

  1. Set the source scope and decide whether frontend, component, backend, and test code are included.
  2. Generate a baseline report and inspect missing statements, branches, and functions in that scope.
  3. Add focused tests for meaningful uncovered behavior, including both sides of important conditions and relevant failure paths.
  4. Review whether each test would detect an incorrect result; remove or improve tests that only inflate execution counts.
  5. Use a threshold in CI only if it reflects your chosen scope and the team’s policy. Keep source-code thresholds distinct from UI Coverage policies.

Do not spend time forcing coverage of generated code, dependencies, or unreachable defensive paths merely to raise a score. If a line is intentionally excluded or genuinely unreachable, document that decision in the project’s coverage configuration or review process.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Source-code coverage is not UI Coverage

Source-code coverage measures execution of instrumented code. Cypress Cloud’s UI Coverage is a separate feature that maps which interactive UI elements tests exercised using Test Replay. It does not replace source-code instrumentation or its statement and branch reports.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The documented UI Coverage setup requires a recorded Cloud run, Test Replay enabled, Cypress v13 or later, and UI Coverage enabled for the organization. Cypress says UI Coverage is not included in standard Cloud plans and offers a trial. Its policies can use fixed thresholds or compare new gaps against a baseline; the results API can be used by a CI job to retrieve results and apply a policy. Treat those UI-element policies separately from NYC source-code coverage thresholds.

Troubleshooting common coverage problems

Symptom Likely cause What to check or do
The report is empty or shows no application files. The browser loaded uninstrumented code, the support import or Node task is missing, or collection is not reaching the task. Confirm the instrumented build is served, the relevant support file imports @cypress/code-coverage/support, and setupNodeEvents registers the task and returns config. Check whether the page has window.__coverage__.
E2E coverage appears, but component coverage does not. The plugin support import exists only in the E2E support file, or the component dev-server build is not instrumented. Import the support module in the component support file and configure Istanbul in the component Vite or Webpack pipeline.
Coverage points to generated files or source lines look wrong. Source maps are missing, stale, or do not correspond to the instrumented build. Verify source maps through transpilation and bundling, then rebuild and rerun tests against matching instrumented assets.
Coverage is counted twice or reports look unexpectedly inflated. More than one build stage may be instrumenting the same code, or global Istanbul configuration may overlap with Jest instrumentation. Use one intentional instrumentation path for each test run and scope Babel/Istanbul to Cypress where needed.
Backend files are absent. The backend was not instrumented or its coverage object was not exposed and fetched. Run the server with coverage instrumentation, expose its counters through middleware or an endpoint, and configure the plugin to retrieve them.
Configuration examples using Cypress.env() fail on a newer setup. The example may predate the Cypress v15.10 configuration migration described by the plugin repository. Check the installed plugin’s v4 migration guidance and the current Cypress version; adapt the configuration to the documented expose approach where applicable.

Or skip the browser setup

If you also need screenshots of pages while developing or documenting a site, ScreenshotNeo is a separate website screenshot API and MCP server; it does not collect Cypress code coverage. One GET request returns an image or PDF. For example, save a screenshot as WebP:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. It can remove cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Cypress automatically instrument my application code?

No. Your build or transpilation setup must add coverage counters before Cypress can collect them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does 100% code coverage prove that my Cypress tests are good?

No. Coverage measures execution, not the quality of assertions or whether tests catch regressions.

Why is my component-test coverage missing when E2E coverage works?

Component tests have a separate support file and build path. Configure the support import and instrumentation for component testing too.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.