• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { spawnPromisified } from '../common/index.mjs';
2import { fileURL, path } from '../common/fixtures.mjs';
3import { match, ok, notStrictEqual, strictEqual } from 'assert';
4import { execPath } from 'node:process';
5import { describe, it } from 'node:test';
6
7
8describe('ESM: thenable loader hooks', { concurrency: true }, () => {
9  it('should behave as a normal promise resolution', async () => {
10    const { code, stderr } = await spawnPromisified(execPath, [
11      '--experimental-loader',
12      fileURL('es-module-loaders', 'thenable-load-hook.mjs').href,
13      path('es-modules', 'test-esm-ok.mjs'),
14    ]);
15
16    strictEqual(code, 0);
17    ok(!stderr.includes('must not call'));
18  });
19
20  it('should crash the node process rejection with an error', async () => {
21    const { code, stderr } = await spawnPromisified(execPath, [
22      '--experimental-loader',
23      fileURL('es-module-loaders', 'thenable-load-hook-rejected.mjs').href,
24      path('es-modules', 'test-esm-ok.mjs'),
25    ]);
26
27    notStrictEqual(code, 0);
28    match(stderr, /\sError: must crash the process\r?\n/);
29    ok(!stderr.includes('must not call'));
30  });
31
32  it('should just reject without an error (but NOT crash the node process)', async () => {
33    const { code, stderr } = await spawnPromisified(execPath, [
34      '--experimental-loader',
35      fileURL('es-module-loaders', 'thenable-load-hook-rejected-no-arguments.mjs').href,
36      path('es-modules', 'test-esm-ok.mjs'),
37    ]);
38
39    notStrictEqual(code, 0);
40    match(stderr, /\sundefined\r?\n/);
41    ok(!stderr.includes('must not call'));
42  });
43});
44