From 28c7791c196d58c64cfdf638b7e68ed1b62a4da0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 24 Jul 2024 13:48:57 -0700 Subject: [PATCH] [Tests] add `process.getBuiltinModule` tests --- test/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 9b35bc9..746e72a 100644 --- a/test/index.js +++ b/test/index.js @@ -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 { @@ -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( @@ -116,6 +131,7 @@ test('core modules', function (t) { } } } + st.end(); });