Skip to content

Commit d40c6b1

Browse files
test: migrate test suite from jest to the node:test runner (#597)
1 parent ac7d7c5 commit d40c6b1

57 files changed

Lines changed: 6227 additions & 9345 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/cross-runtime.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ jobs:
4949
env:
5050
HUSKY: "0"
5151

52+
# jest is no longer a project dev-dep (the Node.js test runner is used
53+
# instead), so install it ad-hoc just for this job. The bridge shim
54+
# (`test/_runner.js`) adapts the suite to jest's globals exactly as it
55+
# does on the legacy-test matrix.
56+
- name: Install jest
57+
run: npm install --no-save --no-package-lock --no-audit jest@^30
58+
5259
- name: Use Deno
5360
uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4
5461
with:

‎.github/workflows/test.yml‎

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
steps:
3535
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
3636

37+
# macOS arm64 runners don't ship Node.js 10/12/14, so force x64.
3738
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
3839
id: calculate_architecture
3940
with:
@@ -50,34 +51,58 @@ jobs:
5051
with:
5152
node-version: ${{ matrix.node-version }}
5253
architecture: ${{ steps.calculate_architecture.outputs.result }}
53-
# Legacy Node (10-16) reinstalls deps after dropping/bypassing
54-
# package-lock.json, so there's no lockfile for setup-node's npm
55-
# cache to key on.
54+
# Legacy Node (10-16) reinstalls deps after dropping the lockfile,
55+
# so there's nothing for setup-node's npm cache to key on.
5656
cache: ${{ (matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x') && '' || 'npm' }}
5757

58-
- name: Install dependencies
58+
# TODO: drop the legacy install + jest steps below once `engines.node`
59+
# is bumped to >= 18. That also makes `jest.config.js`, the jest branch
60+
# of `test/_runner.js`, and `test/polyfill-text-encoding.js` dead code.
61+
#
62+
# The `node:test` based suite needs Node.js 18+; the library itself
63+
# still supports Node.js >= 10.13, so legacy versions run the same test
64+
# files under jest via the runner shim (`test/_runner.js`). jest, memfs
65+
# and the runtime deps are installed ad-hoc so the modern dev toolchain
66+
# (eslint, typescript, prettier) is never required by the legacy leg.
67+
- name: Install jest (Node 10)
68+
if: matrix.node-version == '10.x'
5969
shell: bash
6070
run: |
6171
rm -f package-lock.json
62-
6372
npm config set progress false
73+
yarn add -D jest@^27 memfs@^3 --ignore-scripts --ignore-engines
6474
65-
if [ "${{ matrix.node-version }}" = "10.x" ]; then
66-
yarn add -D typescript@^4 jest@^27 memfs@^3 --ignore-scripts --ignore-engines
67-
else
68-
npm install -g npm@7
69-
npm install -D typescript@^4 jest@^27 memfs@^3 --ignore-scripts --no-audit --prefer-offline --no-save --no-package-lock
70-
fi
71-
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x'
75+
- name: Install jest (Node 12-16)
76+
if: matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x'
77+
shell: bash
78+
run: |
79+
rm -f package-lock.json
80+
npm config set progress false
81+
npm install -g npm@7
82+
npm install -D jest@^27 memfs@^3 --ignore-scripts --no-audit --prefer-offline --no-save --no-package-lock
7283
7384
- name: Install dependencies
74-
run: npm ci
7585
if: matrix.node-version != '10.x' && matrix.node-version != '12.x' && matrix.node-version != '14.x' && matrix.node-version != '16.x'
86+
run: npm ci
87+
88+
- name: Run tests (legacy via jest)
89+
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x'
90+
run: npx jest --ci
91+
92+
# The built-in coverage lcov reporter and `--test-coverage-include` are
93+
# only available on Node.js 22+, so 18/20 run the suite without
94+
# collecting coverage.
95+
- name: Run tests
96+
if: matrix.node-version == '18.x' || matrix.node-version == '20.x'
97+
run: npm run test:only
7698

7799
- name: Run tests with coverage
78-
run: npm run test:coverage -- --ci
100+
if: matrix.node-version == '22.x' || matrix.node-version == '24.x' || matrix.node-version == '25.x'
101+
run: npm run test:coverage
79102

80103
- uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
104+
if: matrix.node-version == '22.x' || matrix.node-version == '24.x' || matrix.node-version == '25.x'
81105
with:
106+
files: ./coverage/lcov.info
82107
flags: integration
83108
token: ${{ secrets.CODECOV_TOKEN }}

‎eslint.config.mjs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,27 @@ export default defineConfig([
2424
},
2525
{
2626
// Cross-runtime smoke scripts run standalone on node/bun/deno and in a
27-
// browser sandbox; relax the library-grade JSDoc typing rules for them.
27+
// browser sandbox; relax library-grade JSDoc rules, allow console
28+
// output (they're CLI scripts) and skip the `engines.node` version
29+
// checks (these files target newer runtimes by design).
2830
files: ["test/smoke/**/*"],
2931
rules: {
3032
"jsdoc/no-restricted-syntax": "off",
3133
"jsdoc/reject-any-type": "off",
3234
"unicorn/prefer-native-coercion-functions": "off",
35+
"n/no-unsupported-features/es-builtins": "off",
36+
"n/no-unsupported-features/es-syntax": "off",
37+
"n/no-unsupported-features/node-builtins": "off",
38+
"no-console": "off",
39+
},
40+
},
41+
{
42+
// The test suite relies on `node:test` and modern `node:assert` helpers,
43+
// which are newer than the `engines.node` range the published library
44+
// targets. Tests are dev-only, so the builtin version check does not apply.
45+
files: ["test/*.js"],
46+
rules: {
47+
"n/no-unsupported-features/node-builtins": "off",
3348
},
3449
},
3550
]);

‎jest.config.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
"use strict";
22

3+
// TODO: drop this file together with `test/_runner.js`'s jest branch and the
4+
// legacy-only steps in the `test` CI job once `engines.node` is bumped to >= 18.
5+
6+
// Jest config is only consumed by the legacy leg of the test matrix
7+
// (Node.js < 18) where `node:test` is not available. Modern runs use
8+
// `node --test` via scripts/test.js and ignore this file.
39
module.exports = {
10+
roots: ["<rootDir>/test"],
411
moduleFileExtensions: ["js", "mjs", "cjs", "ts"],
12+
modulePathIgnorePatterns: ["<rootDir>/test/fixtures/"],
513
setupFiles: ["<rootDir>/test/polyfill-text-encoding.js"],
614
};

0 commit comments

Comments
 (0)