2022-07-29 10:42:55 +02:00
|
|
|
import { spawnPromisified } from '../common/index.mjs';
|
2022-07-17 19:38:43 +02:00
|
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
|
|
import assert from 'node:assert';
|
2022-07-29 10:42:55 +02:00
|
|
|
import { execPath } from 'node:process';
|
|
|
|
import { describe, it } from 'node:test';
|
2022-07-17 19:38:43 +02:00
|
|
|
|
|
|
|
|
2023-02-18 15:26:36 +01:00
|
|
|
describe('ESM: ensure initialization happens only once', { concurrency: true }, () => {
|
2022-07-29 10:42:55 +02:00
|
|
|
it(async () => {
|
|
|
|
const { code, stderr, stdout } = await spawnPromisified(execPath, [
|
2022-07-17 19:38:43 +02:00
|
|
|
'--loader',
|
|
|
|
fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs'),
|
|
|
|
'--no-warnings',
|
|
|
|
fixtures.path('es-modules', 'runmain.mjs'),
|
2022-07-29 10:42:55 +02:00
|
|
|
]);
|
2022-07-17 19:38:43 +02:00
|
|
|
|
2022-07-29 10:42:55 +02:00
|
|
|
// Length minus 1 because the first match is the needle.
|
|
|
|
const resolveHookRunCount = (stdout.match(/resolve passthru/g)?.length ?? 0) - 1;
|
2022-07-17 19:38:43 +02:00
|
|
|
|
2022-07-29 10:42:55 +02:00
|
|
|
assert.strictEqual(stderr, '');
|
|
|
|
/**
|
|
|
|
* resolveHookRunCount = 2:
|
|
|
|
* 1. fixtures/…/runmain.mjs
|
|
|
|
* 2. node:module (imported by fixtures/…/runmain.mjs)
|
|
|
|
*/
|
|
|
|
assert.strictEqual(resolveHookRunCount, 2);
|
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
});
|
|
|
|
});
|