11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst errUnknownBuiltinModuleRE = /^No such built-in module: /u; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// For direct use of require expressions inside of CJS modules, 101cb0ef41Sopenharmony_ci// all kinds of specifiers should work without issue. 111cb0ef41Sopenharmony_ci{ 121cb0ef41Sopenharmony_ci assert.strictEqual(require('fs'), fs); 131cb0ef41Sopenharmony_ci assert.strictEqual(require('node:fs'), fs); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci assert.throws( 161cb0ef41Sopenharmony_ci () => require('node:unknown'), 171cb0ef41Sopenharmony_ci { 181cb0ef41Sopenharmony_ci code: 'ERR_UNKNOWN_BUILTIN_MODULE', 191cb0ef41Sopenharmony_ci message: errUnknownBuiltinModuleRE, 201cb0ef41Sopenharmony_ci }, 211cb0ef41Sopenharmony_ci ); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci assert.throws( 241cb0ef41Sopenharmony_ci () => require('node:internal/test/binding'), 251cb0ef41Sopenharmony_ci { 261cb0ef41Sopenharmony_ci code: 'ERR_UNKNOWN_BUILTIN_MODULE', 271cb0ef41Sopenharmony_ci message: errUnknownBuiltinModuleRE, 281cb0ef41Sopenharmony_ci }, 291cb0ef41Sopenharmony_ci ); 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci// `node:`-prefixed `require(...)` calls bypass the require cache: 331cb0ef41Sopenharmony_ci{ 341cb0ef41Sopenharmony_ci const fakeModule = {}; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci require.cache.fs = { exports: fakeModule }; 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci assert.strictEqual(require('fs'), fakeModule); 391cb0ef41Sopenharmony_ci assert.strictEqual(require('node:fs'), fs); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci delete require.cache.fs; 421cb0ef41Sopenharmony_ci} 43