2022-07-29 08:42:55 +00:00
|
|
|
import { spawnPromisified } from '../common/index.mjs';
|
2022-07-17 17:38:43 +00:00
|
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
|
|
import assert from 'node:assert';
|
2022-07-29 08:42:55 +00:00
|
|
|
import { execPath } from 'node:process';
|
|
|
|
import { describe, it } from 'node:test';
|
2022-07-17 17:38:43 +00:00
|
|
|
|
|
|
|
|
2024-03-23 21:11:28 +00:00
|
|
|
describe('ESM: ensure initialization happens only once', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
2022-07-29 08:42:55 +00:00
|
|
|
it(async () => {
|
|
|
|
const { code, stderr, stdout } = await spawnPromisified(execPath, [
|
2023-07-29 09:51:10 +00:00
|
|
|
'--experimental-import-meta-resolve',
|
2022-07-17 17:38:43 +00:00
|
|
|
'--loader',
|
|
|
|
fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs'),
|
|
|
|
'--no-warnings',
|
|
|
|
fixtures.path('es-modules', 'runmain.mjs'),
|
2022-07-29 08:42:55 +00:00
|
|
|
]);
|
2022-07-17 17:38:43 +00:00
|
|
|
|
2022-07-29 08:42:55 +00:00
|
|
|
assert.strictEqual(stderr, '');
|
|
|
|
/**
|
|
|
|
* resolveHookRunCount = 2:
|
|
|
|
* 1. fixtures/…/runmain.mjs
|
|
|
|
* 2. node:module (imported by fixtures/…/runmain.mjs)
|
2023-07-29 09:51:10 +00:00
|
|
|
* 3. doesnt-matter.mjs (first import.meta.resolve call)
|
|
|
|
* 4. fixtures/…/runmain.mjs (entry point)
|
|
|
|
* 5. doesnt-matter.mjs (second import.meta.resolve call)
|
2022-07-29 08:42:55 +00:00
|
|
|
*/
|
2023-07-29 09:51:10 +00:00
|
|
|
assert.strictEqual(stdout.match(/resolve passthru/g)?.length, 5);
|
2022-07-29 08:42:55 +00:00
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
});
|
|
|
|
});
|