11cb0ef41Sopenharmony_ciimport { spawnPromisified } from '../common/index.mjs'; 21cb0ef41Sopenharmony_ciimport { fileURL, path } from '../common/fixtures.mjs'; 31cb0ef41Sopenharmony_ciimport { match, ok, notStrictEqual, strictEqual } from 'assert'; 41cb0ef41Sopenharmony_ciimport { execPath } from 'node:process'; 51cb0ef41Sopenharmony_ciimport { describe, it } from 'node:test'; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cidescribe('ESM: thenable loader hooks', { concurrency: true }, () => { 91cb0ef41Sopenharmony_ci it('should behave as a normal promise resolution', async () => { 101cb0ef41Sopenharmony_ci const { code, stderr } = await spawnPromisified(execPath, [ 111cb0ef41Sopenharmony_ci '--experimental-loader', 121cb0ef41Sopenharmony_ci fileURL('es-module-loaders', 'thenable-load-hook.mjs').href, 131cb0ef41Sopenharmony_ci path('es-modules', 'test-esm-ok.mjs'), 141cb0ef41Sopenharmony_ci ]); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci strictEqual(code, 0); 171cb0ef41Sopenharmony_ci ok(!stderr.includes('must not call')); 181cb0ef41Sopenharmony_ci }); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci it('should crash the node process rejection with an error', async () => { 211cb0ef41Sopenharmony_ci const { code, stderr } = await spawnPromisified(execPath, [ 221cb0ef41Sopenharmony_ci '--experimental-loader', 231cb0ef41Sopenharmony_ci fileURL('es-module-loaders', 'thenable-load-hook-rejected.mjs').href, 241cb0ef41Sopenharmony_ci path('es-modules', 'test-esm-ok.mjs'), 251cb0ef41Sopenharmony_ci ]); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci notStrictEqual(code, 0); 281cb0ef41Sopenharmony_ci match(stderr, /\sError: must crash the process\r?\n/); 291cb0ef41Sopenharmony_ci ok(!stderr.includes('must not call')); 301cb0ef41Sopenharmony_ci }); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci it('should just reject without an error (but NOT crash the node process)', async () => { 331cb0ef41Sopenharmony_ci const { code, stderr } = await spawnPromisified(execPath, [ 341cb0ef41Sopenharmony_ci '--experimental-loader', 351cb0ef41Sopenharmony_ci fileURL('es-module-loaders', 'thenable-load-hook-rejected-no-arguments.mjs').href, 361cb0ef41Sopenharmony_ci path('es-modules', 'test-esm-ok.mjs'), 371cb0ef41Sopenharmony_ci ]); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci notStrictEqual(code, 0); 401cb0ef41Sopenharmony_ci match(stderr, /\sundefined\r?\n/); 411cb0ef41Sopenharmony_ci ok(!stderr.includes('must not call')); 421cb0ef41Sopenharmony_ci }); 431cb0ef41Sopenharmony_ci}); 44