Skip to content

Commit 7fe3396

Browse files
committed
test(instrumentation-restify): skip testing with Node.js 24 and later
Restify doesn't support Node.js 24. See restify/node-restify#1876 This adds 'SKIP_TEST_IF_NODE_NEWER_THAN' support to the existing scripts/skip-test-if.js and uses that to handle the skipping.
1 parent 5b64b86 commit 7fe3396

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

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"

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)