Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobJingleheimer committed Jul 24, 2022
1 parent f46d557 commit 173279c
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions test/es-module/test-esm-initialization.mjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { spawnSync } from 'node:child_process';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';

import spawn from './helper.spawnAsPromised.mjs';

{ // Verify unadulterated source is loaded when there are no loaders
const { status, stderr, stdout } = spawnSync(
process.execPath,
[

describe('ESM: ensure initialisation happens only once', { concurrency: true }, () => {
it(async () => {
const { code, stderr, stdout } = await spawn(execPath, [
'--loader',
fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs'),
'--no-warnings',
fixtures.path('es-modules', 'runmain.mjs'),
],
{ encoding: 'utf8' },
);
]);

// Length minus 1 because the first match is the needle.
const resolveHookRunCount = (stdout.match(/resolve passthru/g)?.length ?? 0) - 1;
// 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)
*/
assert.strictEqual(resolveHookRunCount, 2);
assert.strictEqual(status, 0);
}
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);
});
});

0 comments on commit 173279c

Please sign in to comment.