Skip to content

Commit 8b131ab

Browse files
authored
fix: coverage reporting (#2763)
1 parent 334adc0 commit 8b131ab

File tree

6 files changed

+119
-27
lines changed

6 files changed

+119
-27
lines changed

.c8rc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"all": true,
3+
"reporter": [
4+
"lcov",
5+
"text",
6+
"html",
7+
"text-summary"
8+
],
9+
"include": [
10+
"lib/**/*.js",
11+
"index.js"
12+
]
13+
}

.github/workflows/nodejs.yml

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3-
4-
51
name: Node CI
62

3+
concurrency:
4+
group: ${{ github.workflow }}
5+
cancel-in-progress: true
6+
77
on:
88
push:
99
branches:
@@ -14,20 +14,63 @@ on:
1414
pull_request:
1515

1616
jobs:
17-
build:
18-
name: Test
19-
uses: pkgjs/action/.github/workflows/[email protected]
20-
with:
21-
runs-on: ubuntu-latest, windows-latest
22-
test-command: npm run coverage:ci
23-
timeout-minutes: 15
24-
post-test-steps: |
25-
- name: Coverage Report
26-
uses: codecov/codecov-action@v4
17+
test:
18+
timeout-minutes: 15
19+
strategy:
20+
fail-fast: false
21+
max-parallel: 0
22+
matrix:
23+
node-version:
24+
- 18
25+
- 20
26+
- 21
27+
runs-on:
28+
- ubuntu-latest
29+
- windows-latest
30+
31+
runs-on: ${{ matrix.runs-on }}
32+
33+
steps:
34+
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
with:
38+
persist-credentials: false
39+
40+
- name: Setup Node.js@${{ matrix.node-version }}
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: ${{ matrix.node-version }}
44+
45+
- name: Print version information
46+
run: |
47+
echo OS: $(node -p "os.version()")
48+
echo Node.js: $(node --version)
49+
echo npm: $(npm --version)
50+
echo git: $(git --version)
51+
52+
- name: Install dependencies
53+
run: npm install
54+
55+
- name: Print installed dependencies
56+
run: npm ls --all
57+
continue-on-error: true
58+
59+
- name: Run tests
60+
run: npm run coverage:ci
61+
env:
62+
CI: true
63+
NODE_V8_COVERAGE: ./coverage/tmp
64+
65+
- name: Coverage Report
66+
uses: codecov/codecov-action@v4
67+
with:
68+
token: ${{ secrets.CODECOV_TOKEN }}
69+
2770
automerge:
2871
if: >
2972
github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
30-
needs: build
73+
needs: test
3174
runs-on: ubuntu-latest
3275
permissions:
3376
pull-requests: write

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ fuzz-results-*.json
7979
# Bundle output
8080
undici-fetch.js
8181
/test/imports/undici-import.js
82+
83+
# .npmrc has platform specific value for windows
84+
.npmrc

package.json

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,28 @@
6767
"build:wasm": "node build/wasm.js --docker",
6868
"lint": "standard | snazzy",
6969
"lint:fix": "standard --fix | snazzy",
70-
"test": "node scripts/generate-pem && npm run test:unit && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:eventsource && npm run test:wpt && npm run test:websocket && npm run test:jest && npm run test:typescript && npm run test:node-test",
71-
"test:cookies": "borp --coverage -p \"test/cookie/*.js\"",
72-
"test:node-fetch": "borp --coverage -p \"test/node-fetch/**/*.js\"",
73-
"test:eventsource": "npm run build:node && borp --expose-gc --coverage -p \"test/eventsource/*.js\"",
74-
"test:fetch": "npm run build:node && borp --expose-gc --coverage -p \"test/fetch/*.js\" && borp --coverage -p \"test/webidl/*.js\"",
75-
"test:jest": "jest",
70+
"test": "npm run test:javascript && cross-env NODE_V8_COVERAGE= npm run test:typescript",
71+
"test:javascript": "node scripts/generate-pem && npm run test:unit && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:eventsource && npm run test:wpt && npm run test:websocket && npm run test:node-test && npm run test:jest",
72+
"test:cookies": "borp -p \"test/cookie/*.js\"",
73+
"test:node-fetch": "borp -p \"test/node-fetch/**/*.js\"",
74+
"test:eventsource": "npm run build:node && borp --expose-gc -p \"test/eventsource/*.js\"",
75+
"test:fetch": "npm run build:node && borp --expose-gc -p \"test/fetch/*.js\" && borp -p \"test/webidl/*.js\"",
76+
"test:jest": "cross-env NODE_V8_COVERAGE= jest",
7677
"test:unit": "borp --expose-gc -p \"test/*.js\"",
77-
"test:node-test": "borp --coverage -p \"test/node-test/**/*.js\"",
78-
"test:tdd": "borp --coverage --expose-gc -p \"test/*.js\"",
78+
"test:node-test": "borp -p \"test/node-test/**/*.js\"",
79+
"test:tdd": "borp --expose-gc -p \"test/*.js\"",
7980
"test:tdd:node-test": "borp -p \"test/node-test/**/*.js\" -w",
8081
"test:typescript": "tsd && tsc --skipLibCheck test/imports/undici-import.ts",
81-
"test:websocket": "borp --coverage -p \"test/websocket/*.js\"",
82+
"test:websocket": "borp -p \"test/websocket/*.js\"",
8283
"test:wpt": "node test/wpt/start-fetch.mjs && node test/wpt/start-FileAPI.mjs && node test/wpt/start-mimesniff.mjs && node test/wpt/start-xhr.mjs && node test/wpt/start-websockets.mjs && node test/wpt/start-cacheStorage.mjs && node test/wpt/start-eventsource.mjs",
83-
"coverage": "nyc --reporter=text --reporter=html npm run test",
84-
"coverage:ci": "nyc --reporter=lcov npm run test",
84+
"coverage": "npm run coverage:clean && cross-env NODE_V8_COVERAGE=./coverage/tmp npm run test && npm run coverage:report",
85+
"coverage:ci": "npm run coverage:clean && cross-env NODE_V8_COVERAGE=./coverage/tmp npm run test && npm run coverage:report:ci",
86+
"coverage:clean": "node ./scripts/clean-coverage.js",
87+
"coverage:report": "cross-env NODE_V8_COVERAGE= c8 report",
88+
"coverage:report:ci": "c8 report",
8589
"bench": "echo \"Error: Benchmarks have been moved to '\/benchmarks'\" && exit 1",
8690
"serve:website": "echo \"Error: Documentation has been moved to '\/docs'\" && exit 1",
87-
"prepare": "husky install",
91+
"prepare": "husky install && node ./scripts/platform-shell.js",
8892
"fuzz": "jsfuzz test/fuzzing/fuzz.js corpus"
8993
},
9094
"devDependencies": {
@@ -93,6 +97,8 @@
9397
"@types/node": "^18.0.3",
9498
"abort-controller": "^3.0.0",
9599
"borp": "^0.9.1",
100+
"c8": "^9.1.0",
101+
"cross-env": "^7.0.3",
96102
"dns-packet": "^5.4.0",
97103
"form-data": "^4.0.0",
98104
"formdata-node": "^6.0.3",

scripts/clean-coverage.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
const { rmSync } = require('node:fs')
4+
const { resolve } = require('node:path')
5+
6+
if (process.env.NODE_V8_COVERAGE) {
7+
if (process.env.NODE_V8_COVERAGE.endsWith('/tmp')) {
8+
rmSync(resolve(__dirname, process.env.NODE_V8_COVERAGE, '..'), { recursive: true, force: true })
9+
} else {
10+
rmSync(resolve(__dirname, process.env.NODE_V8_COVERAGE), { recursive: true, force: true })
11+
}
12+
} else {
13+
console.log(resolve(__dirname, 'coverage'))
14+
rmSync(resolve(__dirname, '../coverage'), { recursive: true, force: true })
15+
}

scripts/platform-shell.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
3+
const { platform } = require('node:os')
4+
const { writeFileSync } = require('node:fs')
5+
const { resolve } = require('node:path')
6+
7+
if (platform() === 'win32') {
8+
writeFileSync(
9+
resolve(__dirname, '.npmrc'),
10+
'script-shell = "C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"\n'
11+
)
12+
}

0 commit comments

Comments
 (0)