forked from cypress-io/code-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextjs.js
28 lines (28 loc) · 778 Bytes
/
nextjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
})
}