All Projects → bahmutov → next-and-cypress-example

bahmutov / next-and-cypress-example

Licence: other
Next.js example instrumented for code coverage from Cypress tests

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to next-and-cypress-example

cypress-example-todomvc-redux
Example TodoMVC application with full code coverage
Stars: ✭ 43 (-61.26%)
Mutual labels:  code-coverage, cypress-example, cypress-code-coverage-example
instrument-cra
Little module for CRA applications to instrument code without ejecting react-scripts
Stars: ✭ 61 (-45.05%)
Mutual labels:  code-coverage, cypress-io
todo-graphql-example
Example Todo app on top of json-graphql-server
Stars: ✭ 20 (-81.98%)
Mutual labels:  cypress-io, cypress-example
nextjs-baseweb
Slightly opinionated scaffold of Next.js and Base Web.
Stars: ✭ 46 (-58.56%)
Mutual labels:  nextjs
Batteries-Included-Next.js
A starting boilerplate for a TS Next.js project with batteries included. Tailwind CSS for styling, Jest and React Testing Library working with path aliases and node-mock-http for API route testing.
Stars: ✭ 35 (-68.47%)
Mutual labels:  nextjs
hn
💻 A personal Hacker News reader using Next.js
Stars: ✭ 43 (-61.26%)
Mutual labels:  nextjs
faeshare
MERN based social media web app made with the help of Next.js, Socket.io and TailwindCSS.
Stars: ✭ 37 (-66.67%)
Mutual labels:  nextjs
Adding-Storyblok-to-NextJS-like-a-Pro
Adding Headless CMS to NextJS like a Pro, this repository contains code examples and guide on how to integrate Storyblok, a headless CMS to NextJS.
Stars: ✭ 23 (-79.28%)
Mutual labels:  nextjs
nextjs-admin-template
Free admin dashboard template based on Next.Js with @paljs/ui component package
Stars: ✭ 266 (+139.64%)
Mutual labels:  nextjs
next-motion
page transitions with nextjs and framer motion api
Stars: ✭ 25 (-77.48%)
Mutual labels:  nextjs
hckrnws
A custom frontend for a better reading experience of HackerNews
Stars: ✭ 20 (-81.98%)
Mutual labels:  nextjs
airbnb-ish
Airbnb UI clone using Next.js + styled-components.
Stars: ✭ 122 (+9.91%)
Mutual labels:  nextjs
instrumentation
Assorted pintools
Stars: ✭ 24 (-78.38%)
Mutual labels:  code-coverage
monorepo-typescript-next-the-sane-way
A monorepo example using TypeScript and Next.js
Stars: ✭ 104 (-6.31%)
Mutual labels:  nextjs
jolvera.dev
Personal blog built with Next.js & Rebass
Stars: ✭ 36 (-67.57%)
Mutual labels:  nextjs
Hangar
Hackathon sponsorship made easy
Stars: ✭ 34 (-69.37%)
Mutual labels:  nextjs
nextjs-ecommerce
Next.js & Keystone.js E-commerce example with TypeScript
Stars: ✭ 59 (-46.85%)
Mutual labels:  nextjs
addtobasic.github.io
CUI Portfolio like ubuntu terminal.
Stars: ✭ 18 (-83.78%)
Mutual labels:  nextjs
nextjs-shopify-auth
Authenticate your Next.js app with Shopify.
Stars: ✭ 54 (-51.35%)
Mutual labels:  nextjs
yearn-comms
Collection of communication, announcements, tweets, newsletters, and other articles about Yearn and a hosted blog for all translation contributors.
Stars: ✭ 16 (-85.59%)
Mutual labels:  nextjs

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 <[email protected]> © 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 <[email protected]>

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].