-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Nextjs example and middleware, close #63
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Middleware for returning server-side code coverage | ||
* for Next.js API route. To use, create new `pages/api/coverage.js` file | ||
* and re-export this default middleware function. | ||
* | ||
``` | ||
// in your pages/api/coverage.js | ||
module.exports = require('@cypress/code-coverage/middleware/nextjs') | ||
// then add to your cypress.json an environment variable pointing at the API | ||
{ | ||
"baseUrl": "http://localhost:3000", | ||
"env": { | ||
"codeCoverage": { | ||
"url": "/api/__coverage__" | ||
} | ||
} | ||
} | ||
``` | ||
* | ||
* @see https://nextjs.org/docs#api-routes | ||
* @see https://github.com/cypress-io/code-coverage | ||
*/ | ||
module.exports = function returnCodeCoverageNext (req, res) { | ||
// only GET is supported | ||
res.status(200).json({ | ||
coverage: global.__coverage__ || null | ||
}) | ||
} |