diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2022-06-18 01:27:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-18 01:27:13 +0100 |
commit | 29236b5c9dd18d7f02bef074abc36096fa5bd70a (patch) | |
tree | fbb4df62c2bbd3b09eaa344890ecb80b477505f8 /test/es-module | |
parent | a36a5469c27a60bc2d9ff590fbf145d59529d9d6 (diff) | |
download | node-new-29236b5c9dd18d7f02bef074abc36096fa5bd70a.tar.gz |
test: improve coverage for load hooks
Refs: https://github.com/nodejs/node/pull/43363#discussion_r894366025
PR-URL: https://github.com/nodejs/node/pull/43374
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Diffstat (limited to 'test/es-module')
-rw-r--r-- | test/es-module/test-esm-loader-thenable.mjs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/es-module/test-esm-loader-thenable.mjs b/test/es-module/test-esm-loader-thenable.mjs new file mode 100644 index 0000000000..c8c3ec2778 --- /dev/null +++ b/test/es-module/test-esm-loader-thenable.mjs @@ -0,0 +1,65 @@ +import { mustCall } from '../common/index.mjs'; +import { fileURL, path } from '../common/fixtures.mjs'; +import { match, ok, notStrictEqual, strictEqual } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +{ + const child = spawn(execPath, [ + '--experimental-loader', + fileURL('es-module-loaders', 'thenable-load-hook.mjs').href, + path('es-modules', 'test-esm-ok.mjs'), + ]); + + let stderr = ''; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (data) => { + stderr += data; + }); + child.on('close', mustCall((code, _signal) => { + strictEqual(code, 0); + ok(!stderr.includes('must not call')); + })); +} + +{ + const child = spawn(execPath, [ + '--experimental-loader', + fileURL('es-module-loaders', 'thenable-load-hook-rejected.mjs').href, + path('es-modules', 'test-esm-ok.mjs'), + ]); + + let stderr = ''; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (data) => { + stderr += data; + }); + child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); + + match(stderr, /\sError: must crash the process\r?\n/); + + ok(!stderr.includes('must not call')); + })); +} + +{ + const child = spawn(execPath, [ + '--experimental-loader', + fileURL('es-module-loaders', 'thenable-load-hook-rejected-no-arguments.mjs').href, + path('es-modules', 'test-esm-ok.mjs'), + ]); + + let stderr = ''; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (data) => { + stderr += data; + }); + child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); + + match(stderr, /\sundefined\r?\n/); + + ok(!stderr.includes('must not call')); + })); +} |