|
1 | 1 | import '../common/index.mjs'; |
2 | 2 | import * as fixtures from '../common/fixtures.mjs'; |
3 | 3 | import assert from 'node:assert'; |
4 | | -import { spawnSync } from 'node:child_process'; |
| 4 | +import { execPath } from 'node:process'; |
| 5 | +import { describe, it } from 'node:test'; |
5 | 6 |
|
| 7 | +import spawn from './helper.spawnAsPromised.mjs'; |
6 | 8 |
|
7 | | -{ // Verify unadulterated source is loaded when there are no loaders |
8 | | - const { status, stderr, stdout } = spawnSync( |
9 | | - process.execPath, |
10 | | - [ |
| 9 | + |
| 10 | +describe('ESM: ensure initialisation happens only once', { concurrency: true }, () => { |
| 11 | + it(async () => { |
| 12 | + const { code, stderr, stdout } = await spawn(execPath, [ |
11 | 13 | '--loader', |
12 | 14 | fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs'), |
13 | 15 | '--no-warnings', |
14 | 16 | fixtures.path('es-modules', 'runmain.mjs'), |
15 | | - ], |
16 | | - { encoding: 'utf8' }, |
17 | | - ); |
| 17 | + ]); |
18 | 18 |
|
19 | | - // Length minus 1 because the first match is the needle. |
20 | | - const resolveHookRunCount = (stdout.match(/resolve passthru/g)?.length ?? 0) - 1; |
| 19 | + // Length minus 1 because the first match is the needle. |
| 20 | + const resolveHookRunCount = (stdout.match(/resolve passthru/g)?.length ?? 0) - 1; |
21 | 21 |
|
22 | | - assert.strictEqual(stderr, ''); |
23 | | - /** |
24 | | - * resolveHookRunCount = 2: |
25 | | - * 1. fixtures/…/runmain.mjs |
26 | | - * 2. node:module (imported by fixtures/…/runmain.mjs) |
27 | | - */ |
28 | | - assert.strictEqual(resolveHookRunCount, 2); |
29 | | - assert.strictEqual(status, 0); |
30 | | -} |
| 22 | + assert.strictEqual(stderr, ''); |
| 23 | + /** |
| 24 | + * resolveHookRunCount = 2: |
| 25 | + * 1. fixtures/…/runmain.mjs |
| 26 | + * 2. node:module (imported by fixtures/…/runmain.mjs) |
| 27 | + */ |
| 28 | + assert.strictEqual(resolveHookRunCount, 2); |
| 29 | + assert.strictEqual(code, 0); |
| 30 | + }); |
| 31 | +}); |
0 commit comments