|
| 1 | +import { mustCall } from '../common/index.mjs'; |
| 2 | +import { fileURL, path } from '../common/fixtures.mjs'; |
| 3 | +import { match, ok, notStrictEqual, strictEqual } from 'assert'; |
| 4 | +import { spawn } from 'child_process'; |
| 5 | +import { execPath } from 'process'; |
| 6 | + |
| 7 | +{ |
| 8 | + const child = spawn(execPath, [ |
| 9 | + '--experimental-loader', |
| 10 | + fileURL('es-module-loaders', 'thenable-load-hook.mjs').href, |
| 11 | + path('es-modules', 'test-esm-ok.mjs'), |
| 12 | + ]); |
| 13 | + |
| 14 | + let stderr = ''; |
| 15 | + child.stderr.setEncoding('utf8'); |
| 16 | + child.stderr.on('data', (data) => { |
| 17 | + stderr += data; |
| 18 | + }); |
| 19 | + child.on('close', mustCall((code, _signal) => { |
| 20 | + strictEqual(code, 0); |
| 21 | + ok(!stderr.includes('must not call')); |
| 22 | + })); |
| 23 | +} |
| 24 | + |
| 25 | +{ |
| 26 | + const child = spawn(execPath, [ |
| 27 | + '--experimental-loader', |
| 28 | + fileURL('es-module-loaders', 'thenable-load-hook-rejected.mjs').href, |
| 29 | + path('es-modules', 'test-esm-ok.mjs'), |
| 30 | + ]); |
| 31 | + |
| 32 | + let stderr = ''; |
| 33 | + child.stderr.setEncoding('utf8'); |
| 34 | + child.stderr.on('data', (data) => { |
| 35 | + stderr += data; |
| 36 | + }); |
| 37 | + child.on('close', mustCall((code, _signal) => { |
| 38 | + notStrictEqual(code, 0); |
| 39 | + |
| 40 | + match(stderr, /\sError: must crash the process\r?\n/); |
| 41 | + |
| 42 | + ok(!stderr.includes('must not call')); |
| 43 | + })); |
| 44 | +} |
| 45 | + |
| 46 | +{ |
| 47 | + const child = spawn(execPath, [ |
| 48 | + '--experimental-loader', |
| 49 | + fileURL('es-module-loaders', 'thenable-load-hook-rejected-no-arguments.mjs').href, |
| 50 | + path('es-modules', 'test-esm-ok.mjs'), |
| 51 | + ]); |
| 52 | + |
| 53 | + let stderr = ''; |
| 54 | + child.stderr.setEncoding('utf8'); |
| 55 | + child.stderr.on('data', (data) => { |
| 56 | + stderr += data; |
| 57 | + }); |
| 58 | + child.on('close', mustCall((code, _signal) => { |
| 59 | + notStrictEqual(code, 0); |
| 60 | + |
| 61 | + match(stderr, /\sundefined\r?\n/); |
| 62 | + |
| 63 | + ok(!stderr.includes('must not call')); |
| 64 | + })); |
| 65 | +} |
0 commit comments