Skip to content

Commit

Permalink
test: fix es-module/test-esm-initialization
Browse files Browse the repository at this point in the history
PR-URL: #48880
Backport-PR-URL: #50669
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
aduh95 authored and targos committed Nov 23, 2023
1 parent 14e148e commit f02637e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/es-module/test-esm-initialization.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import { describe, it } from 'node:test';
describe('ESM: ensure initialization happens only once', { concurrency: true }, () => {
it(async () => {
const { code, stderr, stdout } = await spawnPromisified(execPath, [
'--experimental-import-meta-resolve',
'--loader',
fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs'),
'--no-warnings',
fixtures.path('es-modules', 'runmain.mjs'),
]);

// Length minus 1 because the first match is the needle.
const resolveHookRunCount = (stdout.match(/resolve passthru/g)?.length ?? 0) - 1;

assert.strictEqual(stderr, '');
/**
* resolveHookRunCount = 2:
* 1. fixtures/…/runmain.mjs
* 2. node:module (imported by fixtures/…/runmain.mjs)
* 3. doesnt-matter.mjs (first import.meta.resolve call)
* 4. fixtures/…/runmain.mjs (entry point)
* 5. doesnt-matter.mjs (second import.meta.resolve call)
*/
assert.strictEqual(resolveHookRunCount, 2);
assert.strictEqual(stdout.match(/resolve passthru/g)?.length, 5);
assert.strictEqual(code, 0);
});
});

0 comments on commit f02637e

Please sign in to comment.