Skip to content

Commit

Permalink
[New] add node:test, in node 18+
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 19, 2022
1 parent d6ed201 commit f853eca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"files": "test/**",
"rules": {
"global-require": 0,
"max-depth": 0,
"max-lines-per-function": 0,
"no-negated-condition": 0,
},
Expand Down
1 change: 1 addition & 0 deletions core.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"node:string_decoder": [">= 14.18 && < 15", ">= 16"],
"sys": [">= 0.4 && < 0.7", ">= 0.8"],
"node:sys": [">= 14.18 && < 15", ">= 16"],
"node:test": ">= 18",
"timers": true,
"node:timers": [">= 14.18 && < 15", ">= 16"],
"timers/promises": ">= 15",
Expand Down
48 changes: 28 additions & 20 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ test('core modules', function (t) {
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);
if (supportsNodePrefix) {
st.doesNotThrow(
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' does not throw'
);
} else {
st['throws'](
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' throws'
);
if (mod.slice(0, 5) !== 'node:') {
if (supportsNodePrefix) {
st.doesNotThrow(
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' does not throw'
);
} else {
st['throws'](
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' throws'
);
}
}
}
}
Expand All @@ -81,6 +83,10 @@ test('core modules', function (t) {
'v8/tools/tickprocessor',
'v8/tools/profile'
];
// see https://github.com/nodejs/node/issues/42785
if (semver.satisfies(process.version, '>= 18')) {
libs = libs.concat('node:test');
}
for (var i = 0; i < libs.length; ++i) {
var mod = libs[i];
if (excludeList.indexOf(mod) === -1) {
Expand All @@ -89,16 +95,18 @@ test('core modules', function (t) {
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);
if (supportsNodePrefix) {
st.doesNotThrow(
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' does not throw'
);
} else {
st['throws'](
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' throws'
);
if (mod.slice(0, 5) !== 'node:') {
if (supportsNodePrefix) {
st.doesNotThrow(
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' does not throw'
);
} else {
st['throws'](
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
'requiring node:' + mod + ' throws'
);
}
}
}
}
Expand Down

0 comments on commit f853eca

Please sign in to comment.