RepositoryJavaScriptUSUnited States
bahmutov

bahmutov/next-and-cypress-example

Next.js example instrumented for code coverage from Cypress tests

137stars
22forks
9issues
2views

next.js and Cypress example renovate-app badge CircleCI

Next.js example instrumented for code coverage from Cypress tests

Install and run

npm install
npm run e2e

This starts the application at localhost:3000 and opens Cypress test runner.

npm run e2e

Click on the spec file to run the end-to-end tests.

all tests

Coverage

The tests are instrumented following the instructions in Cypress code coverage guide. In particular, the front-end is instrumented using .babelrc file like

{
  "presets": ["next/babel"],
  "plugins": ["istanbul"]
}

When you run tests, the code coverage report is saved in coverage folder. There are reports in several formats, but open the HTML one for human-readable report.

$ open coverage/lcov-report/index.html

Code coverage report

To fetch the server-side code coverage, the @cypress/code-coverage plugin needs an endpoint. This endpoint is implemented in pages/api/coverage.js file following the Next.js API convention. This endpoint just returns the existing global coverage object or null

export default (req, res) => {
  res.status(200).json({
    coverage: global.__coverage__ || null
  })
}

Cypress plugin requests the right endpoint using the environment variable from cypress.json file

{
  "baseUrl": "http://localhost:3000",
  "env": {
    "codeCoverage": {
      "url": "/api/__coverage__"
    }
  }
}

On CI after the tests finish, we store the coverage reports. We also run a script to check if the coverage dropped below 100%

$ npx nyc report --reporter=text-summary --check-coverage --statements 100
================== Coverage summary =========
Statements   : 100% ( 22/22 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 9/9 )
Lines        : 100% ( 22/22 )
=============================================

See more

Small print

Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2019

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2019 Gleb Bahmutov <gleb.bahmutov@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Similar Projects

Discover other similar projects and AI models.

RepositoryJavaScript
elaichenkov/cy-verify-downloads

Cypress custom command to wait and verify that file has been downloaded

71
Jan 26, 2026
RepositoryJavaScript
Shelex/cypress-allure-plugin-example

example of cypress + cypress-allure-plugin + github action as CI + allure hosted as github page, report:

53
Mar 28, 2025
RepositoryTypeScript
bahmutov/test-todomvc-using-app-actions

Example Cypress tests going from page objects to app actions

103
Nov 16, 2026
RepositoryTypeScript
riccardogiorato/cypress-for-everything

Cypress to test everything! - Do all kind of tests with Cypress ranging from Http Redirects, Seo, Logins, Emails and much more!

79
Apr 14, 2026
RepositoryJavaScript
vercel/next.js

The React Framework

143.9k
Dec 1, 2026
RepositoryJavaScript
vercel/next.js

The React Framework

143.9k
Dec 1, 2026
RepositoryPython
langgenius/dify

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

162.3k
Dec 2, 2026
RepositoryTypeScript
shadcn-ui/ui

Composable, accessible components with thoughtful defaults. Build your own component library with code you can customize, extend, and make your own.

129.8k
Dec 2, 2026
Modelsentence-similarity
sentence-transformers/all-MiniLM-L6-v2

all-MiniLM-L6-v2 This is a sentence-transformers(https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. Usage (Sentence-Transformers) Using t...

♥0
157.6M
Jun 1, 2026