Skip to content

Commit

Permalink
[Tests] add process.getBuiltinModule tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 24, 2024
1 parent 8ec3366 commit 28c7791
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ test('core modules', function (t) {
});

t.test('core via builtinModules list', { skip: !data.module }, function (st) {
var libs = require('module').builtinModules;
var Module = require('module');
var libs = Module.builtinModules;
if (!libs) {
st.skip('module.builtinModules does not exist');
} else {
Expand All @@ -96,10 +97,24 @@ test('core modules', function (t) {
var mod = libs[i];
if (excludeList.indexOf(mod) === -1) {
st.ok(data[mod], mod + ' is a core module');

if (Module.isBuiltin) {
st.ok(Module.isBuiltin(mod), 'module.isBuiltin(' + mod + ') is true');
}

st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);

if (process.getBuiltinModule) {
st.equal(
process.getBuiltinModule(mod),
require(mod),
'process.getBuiltinModule(' + mod + ') === require(' + mod + ')'
);
}

if (mod.slice(0, 5) !== 'node:') {
if (supportsNodePrefix) {
st.doesNotThrow(
Expand All @@ -116,6 +131,7 @@ test('core modules', function (t) {
}
}
}

st.end();
});

Expand Down

0 comments on commit 28c7791

Please sign in to comment.