Skip to content

Commit dccde95

Browse files
committed
feat: adds script to run tests with node 20 correctly
1 parent 008c2fa commit dccde95

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

lib/content/_step-test-yml.hbs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
- name: Test (with coverage on Node >= 24)
77
if: $\{{ startsWith(matrix.node-version, '24') }}
88
run: {{ rootNpmPath }} run test:cover --ignore-scripts {{~#if jobRunFlags}} {{ jobRunFlags }}{{/if}}
9-
- name: Test (without coverage on Node < 24)
10-
if: $\{{ !startsWith(matrix.node-version, '24') }}
9+
- name: Test (on Node 20 with globbing workaround)
10+
if: $\{{ startsWith(matrix.node-version, '20') }}
11+
run: {{ rootNpmPath }} run test:node20 --ignore-scripts {{~#if jobRunFlags}} {{ jobRunFlags }}{{/if}}
12+
- name: Test
13+
if: $\{{ !startsWith(matrix.node-version, '24') && !startsWith(matrix.node-version, '20') }}
1114
run: {{ rootNpmPath }} test --ignore-scripts {{~#if jobRunFlags}} {{ jobRunFlags }}{{/if}}
1215
{{else}}
1316
- name: Test

lib/content/package-json.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
{{#if isNodeTest}}
2121
"snap": "node --test --test-update-snapshots './test/**/*.js'",
2222
"test": "node --test './test/**/*.js'",
23+
"test:node20": "node --test test",
2324
"test:cover": "node --test --experimental-test-coverage --test-timeout=3000{{#if coverageThreshold}} --test-coverage-lines={{coverageThreshold}} --test-coverage-functions={{coverageThreshold}} --test-coverage-branches={{coverageThreshold}}{{/if}} './test/**/*.js'",
2425
{{else}}
2526
"snap": "{{#if typescript}}{{#if tap16}}c8 {{/if}}{{/if}}tap",

test/apply/node-test-ci.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ t.test('CI workflow with node:test does not include tap matcher', async t => {
2020

2121
// Verify conditional test steps for coverage
2222
t.match(ciWorkflow, /Test \(with coverage on Node >= 24\)/, 'should have test with coverage step for Node >= 24')
23-
t.match(ciWorkflow, /Test \(without coverage on Node < 24\)/, 'should have test without coverage step for Node < 24')
23+
t.match(ciWorkflow, /Test \(on Node 20 with globbing workaround\)/, 'should have test:node20 step for Node 20')
24+
t.match(ciWorkflow, /- name: Test\n\s+if:/, 'should have regular test step for other Node versions')
2425
t.match(ciWorkflow, "startsWith(matrix.node-version, '24')", 'should check if Node version starts with 24')
25-
t.match(ciWorkflow, "!startsWith(matrix.node-version, '24')", 'should check if Node version does not start with 24')
26+
t.match(ciWorkflow, "startsWith(matrix.node-version, '20')", 'should check if Node version starts with 20')
2627
t.match(ciWorkflow, /test:cover/, 'should use test:cover script for Node >= 24')
28+
t.match(ciWorkflow, /test:node20/, 'should use test:node20 script for Node 20')
2729
})
2830

2931
t.test('CI workflow with tap includes tap matcher', async t => {

test/apply/node-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ t.test('node:test runner', async t => {
1616

1717
// Verify test scripts are for node:test
1818
t.equal(pkg.scripts.test, "node --test './test/**/*.js'")
19+
t.equal(pkg.scripts['test:node20'], 'node --test test')
1920
t.equal(
2021
pkg.scripts['test:cover'],
2122
"node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=100 --test-coverage-functions=100 --test-coverage-branches=100 './test/**/*.js'",
@@ -52,6 +53,7 @@ t.test('node:test runner with incomplete coverage', async t => {
5253

5354
// Verify test scripts are for node:test
5455
t.equal(pkg.scripts.test, "node --test './test/**/*.js'")
56+
t.equal(pkg.scripts['test:node20'], 'node --test test')
5557
t.equal(
5658
pkg.scripts['test:cover'],
5759
"node --test --experimental-test-coverage --test-timeout=3000 './test/**/*.js'",

0 commit comments

Comments
 (0)