0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-shadow-realm-custom-loaders.js
Chengzhong Wu fc2862b7f5
module: bootstrap module loaders in shadow realm
This bootstraps ESM loaders in the ShadowRealm with
`ShadowRealm.prototype.importValue` as its entry point and enables
loading ESM and CJS modules in the ShadowRealm. The module is imported
without a parent URL and resolved with the current process's working
directory.

PR-URL: https://github.com/nodejs/node/pull/48655
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-11-13 22:09:47 +08:00

27 lines
783 B
JavaScript

'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const commonArgs = [
'--experimental-shadow-realm',
'--no-warnings',
];
async function main() {
// Verifies that custom loaders are not enabled in the ShadowRealm.
const child = await common.spawnPromisified(process.execPath, [
...commonArgs,
'--experimental-loader',
fixtures.fileURL('es-module-loaders', 'loader-resolve-shortcircuit.mjs'),
'--experimental-loader',
fixtures.fileURL('es-module-loaders', 'loader-load-foo-or-42.mjs'),
fixtures.path('es-module-shadow-realm', 'custom-loaders.js'),
]);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
}
main().then(common.mustCall());