Skip to content

Commit 5ae1288

Browse files
committed
use dist paths
1 parent 7d396ba commit 5ae1288

File tree

9 files changed

+50
-61
lines changed

9 files changed

+50
-61
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ dist/
88
cypress-coverage/
99
yarn.lock
1010
.parcel-cache
11+
12+
13+
# dist
14+
./*.js
15+
./middleware
16+
./lib

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Then add the code below to the `supportFile` and `setupNodeEvents` function.
1414

1515
```js
1616
// cypress/support/e2e.js
17-
import 'cypress-code-coverage-v8/support'
17+
import 'cypress-code-coverage-v8/dist/support'
1818
```
1919

2020
```js
@@ -26,7 +26,7 @@ module.exports = defineConfig({
2626
// the e2e or component configuration
2727
e2e: {
2828
setupNodeEvents(on, config) {
29-
require('cypress-code-coverage-v8/plugins')(on, config)
29+
require('cypress-code-coverage-v8/dist/plugins')(on, config)
3030
// include any other plugin code...
3131

3232
// It's IMPORTANT to return the config object
@@ -131,7 +131,7 @@ You can also instrument your server-side code and produce a combined coverage re
131131
```js
132132
const express = require('express')
133133
const app = express()
134-
require('cypress-code-coverage-v8/middleware/express')(app)
134+
require('cypress-code-coverage-v8/dist/middleware/express')(app)
135135
```
136136

137137
For any other server, define the endpoint yourself and return the coverage object:

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,6 @@
33
"version": "0.0.0-development",
44
"description": "Saves the code coverage collected during Cypress tests",
55
"main": "dist/support.js",
6-
"exports": {
7-
".": {
8-
"default": "./dist/support.js",
9-
"types": "./dist/support.d.ts"
10-
},
11-
"./*": {
12-
"default": "./dist/*.js",
13-
"types": "./dist/*.d.ts"
14-
},
15-
"./middleware/*": {
16-
"default": "./dist/middleware/*.js",
17-
"types": "./dist/middleware/*.d.ts"
18-
},
19-
"./plugins": {
20-
"default": "./dist/plugins.js",
21-
"types": "./dist/plugins.d.ts"
22-
},
23-
"./register": {
24-
"default": "./dist/register.js",
25-
"types": "./dist/register.d.ts"
26-
},
27-
"./support": {
28-
"default": "./dist/support.js",
29-
"types": "./dist/support.d.ts"
30-
}
31-
},
326
"scripts": {
337
"start": "parcel serve cypress/index.html",
348
"coverage:verify": "npx nyc report --check-coverage true --lines 80",
@@ -91,7 +65,7 @@
9165
"@types/debug": "^4.1.12",
9266
"@types/express": "^4.17.21",
9367
"@types/js-yaml": "^4.0.9",
94-
"@types/koa": "^2.15.0",
68+
"@types/koa": "2.13.4",
9569
"@types/node": "^20.11.19",
9670
"check-code-coverage": "1.10.5",
9771
"console-log-div": "0.6.3",

src/middleware/express.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
const { isCoverageEnabled } = require('../lib/common/isEnabled')
2-
const { debug } = require('../lib/common/common-utils');
2+
const { debug } = require('../lib/common/common-utils')
33

44
/**
55
* for Express.js
66
*
77
* @example Use like
88
* ```ts
9+
* require('cypress-code-coverage-v8/dist/register');
910
* const express = require('express')
1011
* const app = express()
1112
* // @see https://github.com/rohit-gohri/cypress-code-coverage-v8
12-
* require('cypress-code-coverage-v8/middleware/express')(app)
13+
* require('cypress-code-coverage-v8/dist/middleware/express')(app)
1314
* ```
1415
*
1516
* Then add to your cypress.json an environment variable pointing at the API
@@ -23,7 +24,7 @@ const { debug } = require('../lib/common/common-utils');
2324
* }
2425
* }
2526
* ```
26-
*
27+
*
2728
* @param {import('express').Application} app
2829
*/
2930
module.exports = (app) => {
@@ -32,9 +33,7 @@ module.exports = (app) => {
3233
return
3334
}
3435

35-
const {
36-
takePreciseCoverage
37-
} = require('../lib/register/v8Interface')
36+
const { takePreciseCoverage } = require('../lib/register/v8Interface')
3837

3938
// expose "GET __coverage__" endpoint that just returns
4039
// global coverage information (if the application has been instrumented)

src/middleware/hapi.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const { isCoverageEnabled } = require('../lib/common/isEnabled')
2-
const { debug } = require('../lib/common/common-utils');
2+
const { debug } = require('../lib/common/common-utils')
33

44
/**
55
* for Hapi.js
66
*
77
* * @example Use like
88
* ```ts
9+
* require('cypress-code-coverage-v8/dist/register');
910
* const Hapi = require('@hapi/hapi');
10-
* const coverageRoutes = require('cypress-code-coverage-v8/middleware/hapi');
11+
* const coverageRoutes = require('cypress-code-coverage-v8/dist/middleware/hapi');
1112
*
1213
* const init = async () => {
1314
* const server = Hapi.server({
@@ -22,7 +23,7 @@ const { debug } = require('../lib/common/common-utils');
2223
* console.log('Server running on %s', server.info.uri);
2324
* };
2425
* ```
25-
*
26+
*
2627
* Then add to your cypress.json an environment variable pointing at the API
2728
* ```json
2829
* {
@@ -53,7 +54,6 @@ module.exports = (server) => {
5354
method: 'GET',
5455
path: '/__coverage__',
5556
async handler() {
56-
5757
return { coverage: (await takePreciseCoverage()) || null }
5858
}
5959
})

src/middleware/koa.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
const { isCoverageEnabled } = require('../lib/common/isEnabled')
2-
const { debug } = require('../lib/common/common-utils');
2+
const { debug } = require('../lib/common/common-utils')
33

44
/**
55
* for Koa
66
*
77
* @example Use like
8-
*
8+
*
99
* ```ts
10-
* require('cypress-code-coverage-v8/register');
10+
* require('cypress-code-coverage-v8/dist/register');
1111
* const Koa = require('koa')
1212
* const app = new Koa();
1313
* // @see https://github.com/rohit-gohri/cypress-code-coverage-v8
14-
* require('cypress-code-coverage-v8/middleware/koa')(app)
14+
* require('cypress-code-coverage-v8/dist/middleware/koa')(app)
1515
* ```
16-
*
16+
*
1717
* Then add to your cypress.json an environment variable pointing at the API
1818
* ```json
1919
* {
@@ -34,7 +34,7 @@ module.exports = (app) => {
3434
return
3535
}
3636
debug('adding koa middleware, code coverage is enabled')
37-
37+
3838
const { takePreciseCoverage } = require('../lib/register/v8Interface')
3939
// expose "GET __coverage__" endpoint that just returns
4040
// global coverage information (if the application has been instrumented)

src/middleware/nextjs.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ if (isCoverageEnabled()) {
1111
*
1212
* @example in your pages/api/__coverage__.js
1313
* ```ts
14-
* import coverageHandler from 'cypress-code-coverage-v8/middleware/nextjs';
14+
* import coverageHandler from 'cypress-code-coverage-v8/dist/middleware/nextjs';
1515
* export default coverageHandler;
1616
* ```
17-
*
17+
*
1818
* Then add to your cypress.json an environment variable pointing at the API
1919
* ```json
2020
* {
@@ -29,7 +29,7 @@ if (isCoverageEnabled()) {
2929
*
3030
* @see https://nextjs.org/docs#api-routes
3131
* @see https://github.com/rohit-gohri/cypress-code-coverage-v8
32-
*
32+
*
3333
* @param {import('next').NextApiRequest} _req
3434
* @param {import('next').NextApiResponse} res
3535
*/
@@ -42,9 +42,19 @@ module.exports = async function returnCodeCoverageNext(_req, res) {
4242
}
4343

4444
const { takePreciseCoverage } = require('../lib/register/v8Interface')
45+
const coverage = await takePreciseCoverage()
4546

46-
// only GET is supported
47-
res.status(200).json({
48-
coverage: (await takePreciseCoverage()) || null
49-
})
47+
if (!coverage) {
48+
// only GET is supported
49+
res.status(200).json({
50+
coverage: null
51+
})
52+
} else {
53+
console.error(coverage)
54+
// TODO: Convert webpack paths to files, convert package alias to file path
55+
// example:
56+
res.status(200).json({
57+
coverage
58+
})
59+
}
5060
}

src/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const addTasks = require('./lib/plugin/task')
1010
// your plugins file
1111
1212
module.exports = (on, config) => {
13-
require('cypress-code-coverage-v8/plugins').coveragePlugin(on, config)
13+
require('cypress-code-coverage-v8/dist/plugins').coveragePlugin(on, config)
1414
// IMPORTANT to return the config object
1515
// with the any changed environment variables
1616
return config

0 commit comments

Comments
 (0)