Skip to content

Commit e6c29be

Browse files
authored
ci: test against Node.js 24 (#2984)
Now that the mocha + ts-node + Node automatic type-stripping thing is (mostly) sorted, we should be able to test with Node.js 24 now. Some special cases: - restify doesn't support Node.js v24, so scripts/skip-test-if.js was improved and used to skip restify tests when using Node.js 24 - the transitive better-sqlite3 dep needed a bug in minor version to compile against Node.js v24 - shockingly tedious@1 (from 2017) doesn't support Node.js v24, so we skip that combo in the test-all-versions tests
1 parent 01e507f commit e6c29be

File tree

8 files changed

+62
-27
lines changed

8 files changed

+62
-27
lines changed

.github/workflows/test-all-versions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
strategy:
5252
fail-fast: false
5353
matrix:
54-
node: ["18", "20", "22"]
54+
node: ["18", "20", "22", "24"]
5555
runs-on: ubuntu-latest
5656
services:
5757
mongo:

.github/workflows/unit-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
- "20.6.0"
4949
- "20"
5050
- "22"
51+
- "24"
5152
include:
5253
- node: 18
5354
code-coverage: true

package-lock.json

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

packages/instrumentation-knex/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@opentelemetry/sdk-trace-node": "^2.0.0",
5454
"@types/mocha": "10.0.10",
5555
"@types/node": "18.18.14",
56-
"better-sqlite3": "11.0.0",
56+
"better-sqlite3": "^11.10.0",
5757
"knex": "3.1.0",
5858
"nyc": "17.1.0",
5959
"rimraf": "5.0.10",

packages/instrumentation-restify/.tav.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ restify:
22
- versions:
33
include: '>=10.0.0 <12'
44
mode: latest-minors
5-
node: ">=18"
5+
node: ">=18 <24"
66
commands: npm run test
7+
env:
8+
- SKIP_TEST_IF_DISABLED=true
79

810
- versions:
911
include: '>=4.1.0 <10'
1012
mode: max-7
1113
node: "<18"
1214
commands: npm run test
15+
env:
16+
- SKIP_TEST_IF_DISABLED=true

packages/instrumentation-restify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"lint:readme": "node ../../scripts/lint-readme.js",
1919
"prepublishOnly": "npm run compile",
2020
"tdd": "yarn test -- --watch-extensions ts --watch",
21-
"test": "nyc mocha 'test/**/*.ts'",
21+
"test": "SKIP_TEST_IF_NODE_NEWER_THAN=23 nyc mocha --require '../../scripts/skip-test-if.js' 'test/**/*.ts'",
2222
"test-all-versions": "tav",
2323
"version:update": "node ../../scripts/version-update.js",
2424
"watch": "tsc -w"

packages/instrumentation-tedious/.tav.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
tedious:
22
- versions:
3-
include: ">=1.11.0 <12"
3+
include: ">=1.11.0 <2"
4+
mode: latest-majors
5+
# tedious@1 uses tls.createSecurePair() which was removed in Node.js 24
6+
# (https://nodejs.org/api/all.html#DEP0064).
7+
node: "<24"
8+
commands: npm run test
9+
- versions:
10+
include: ">=2 <12"
411
# 4.0.0 is broken: https://github.com/tediousjs/tedious/commit/4eceb48
512
exclude: "4.0.0"
613
mode: latest-majors

scripts/skip-test-if.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,62 @@
1616

1717
/**
1818
* This script can be used with `mocha --require ...` to support skipping
19-
* tests if the current version of Node.js is too old. For example, say
20-
* a package's unit tests cannot run with Node.js 14, but the CI unit tests
21-
* run all package test with that version.
19+
* tests if the current version of Node.js is too old or too new. For example,
20+
* say a package's unit tests cannot run with Node.js 14, but the CI unit tests
21+
* run all package tests with that version.
2222
*
2323
* 1. Change this in "package.json":
2424
* "test": "nyc mocha ...",
25-
* to this:
26-
* "test": "SKIP_TEST_IF_NODE_OLDER_THAN=18 nyc mocha --require '../../../scripts/skip-test-if.js' ... ",
27-
* where `SKIP_TEST_IF_NODE_OLDER_THAN` indicates the minimum Node.js major
28-
* version.
25+
* to one of these:
26+
* "test": "SKIP_TEST_IF_NODE_OLDER_THAN=18 nyc mocha --require '../../scripts/skip-test-if.js' ...",
27+
* "test": "SKIP_TEST_IF_NODE_NEWER_THAN=22 nyc mocha --require '../../scripts/skip-test-if.js' ...",
28+
* where `SKIP_TEST_IF_NODE_{OLDER|NEWER}_THAN` indicates a Node.js *major*
29+
* version number.
2930
*
30-
* 2. ".tav.yml" blocks should set SKIP_TEST_IF_DISABLE=true to
31+
* 2. ".tav.yml" blocks should set SKIP_TEST_IF_DISABLED=true to
3132
* disable the skipping. Via this in each test block:
3233
* env:
33-
* - SKIP_TEST_IF_DISABLE=true
34+
* - SKIP_TEST_IF_DISABLED=true
3435
*/
3536

3637
function skipTestIf() {
37-
if (process.env.SKIP_TEST_IF_DISABLE) {
38+
if (process.env.SKIP_TEST_IF_DISABLED) {
3839
return;
3940
}
4041

41-
const minNodeMajor = process.env.SKIP_TEST_IF_NODE_OLDER_THAN ?? Number(process.env.SKIP_TEST_IF_NODE_OLDER_THAN);
42-
if (!minNodeMajor || isNaN(minNodeMajor)) {
43-
console.warn('skip-test-if warning: set a minimum Node.js major version via SKIP_TEST_IF_NODE_OLDER_THAN=<num>');
42+
let minNodeMajor;
43+
if (process.env.SKIP_TEST_IF_NODE_OLDER_THAN) {
44+
minNodeMajor = Number(process.env.SKIP_TEST_IF_NODE_OLDER_THAN)
45+
if (isNaN(minNodeMajor) || !Number.isInteger(minNodeMajor)) {
46+
console.warn(`skip-test-if warning: ignoring invalid SKIP_TEST_IF_NODE_OLDER_THAN value: "${process.env.SKIP_TEST_IF_NODE_OLDER_THAN}"`);
47+
minNodeMajor = undefined;
48+
}
49+
}
50+
let maxNodeMajor;
51+
if (process.env.SKIP_TEST_IF_NODE_NEWER_THAN) {
52+
maxNodeMajor = Number(process.env.SKIP_TEST_IF_NODE_NEWER_THAN)
53+
if (isNaN(maxNodeMajor) || !Number.isInteger(maxNodeMajor)) {
54+
console.warn(`skip-test-if warning: ignoring invalid SKIP_TEST_IF_NODE_NEWER_THAN value: "${process.env.SKIP_TEST_IF_NODE_NEWER_THAN}"`);
55+
maxNodeMajor = undefined;
56+
}
57+
}
58+
59+
if (minNodeMajor === undefined && maxNodeMajor === undefined) {
60+
console.warn('skip-test-if warning: skip-test-if.js was used, but no SKIP_TEST_IF_* envvars were set');
4461
return;
4562
}
4663

4764
const nodeMajor = Number(process.versions.node.split('.')[0]);
48-
if (nodeMajor < minNodeMajor) {
65+
if (minNodeMajor && nodeMajor < minNodeMajor) {
4966
process.stderr.write(`skip-test-if: skipping tests on old Node.js (${nodeMajor} < ${minNodeMajor})\n`);
5067
// "Skip" tests by exiting the process. Mocha is all in one process.
5168
process.exit(0);
5269
}
70+
if (maxNodeMajor && nodeMajor > maxNodeMajor) {
71+
process.stderr.write(`skip-test-if: skipping tests on too-new Node.js (${nodeMajor} > ${maxNodeMajor})\n`);
72+
// "Skip" tests by exiting the process. Mocha is all in one process.
73+
process.exit(0);
74+
}
5375
}
5476

5577
skipTestIf()

0 commit comments

Comments
 (0)