/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v26.2.0
test/es-module/test-require-module-preload.js
113 строк
2 KB
Antoine du Hamel
test: forbid use of named imports for fixtures
02 янв 2026, 02:48
Не верифицирован
02 янв 2026, 02:48
0457bfe
Код
Авторство
О чём код?
'use strict'; require('../common'); const { spawnSyncAndAssert } = require('../common/child_process'); const fixtures = require('../common/fixtures'); function testPreload(preloadFlag) { // Test named exports. { spawnSyncAndAssert( process.execPath, [ '--experimental-require-module', preloadFlag, './es-module-loaders/module-named-exports.mjs', './printA.js', ], { cwd: fixtures.fixturesDir, }, { stdout: 'A', trim: true, } ); } // Test ESM that import ESM. { spawnSyncAndAssert( process.execPath, [ '--experimental-require-module', preloadFlag, './es-modules/import-esm.mjs', './printA.js', ], { cwd: fixtures.fixturesDir, }, { stdout: /^world\s+A$/, trim: true, } ); } // Test ESM that import CJS. { spawnSyncAndAssert( process.execPath, [ '--experimental-require-module', preloadFlag, './es-modules/cjs-exports.mjs', './printA.js', ], { cwd: fixtures.fixturesDir, }, { stdout: /^ok\s+A$/, trim: true, } ); } // Test ESM that require() CJS. // Can't use the common/index.mjs here because that checks the globals, and // -r injects a bunch of globals. { spawnSyncAndAssert( process.execPath, [ '--experimental-require-module', preloadFlag, './es-modules/require-cjs.mjs', './printA.js', ], { cwd: fixtures.fixturesDir, }, { stdout: /^world\s+A$/, trim: true, } ); } } testPreload('--require'); testPreload('--import'); // Test "type": "module" and "main" field in package.json, this is only for --require because // --import does not support extension-less preloads. { spawnSyncAndAssert( process.execPath, [ '--experimental-require-module', '--require', './es-modules/package-type-module', './printA.js', ], { cwd: fixtures.fixturesDir, }, { stdout: /^package-type-module\s+A$/, trim: true, } ); }