11cb0ef41Sopenharmony_ciimport { spawnPromisified } from '../common/index.mjs'; 21cb0ef41Sopenharmony_ciimport * as fixtures from '../common/fixtures.mjs'; 31cb0ef41Sopenharmony_ciimport assert from 'node:assert'; 41cb0ef41Sopenharmony_ciimport { execPath } from 'node:process'; 51cb0ef41Sopenharmony_ciimport { describe, it } from 'node:test'; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// Expect note to be included in the error output 91cb0ef41Sopenharmony_ciconst expectedNote = 'To load an ES module, ' + 101cb0ef41Sopenharmony_ci'set "type": "module" in the package.json ' + 111cb0ef41Sopenharmony_ci'or use the .mjs extension.'; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst mustIncludeMessage = { 141cb0ef41Sopenharmony_ci getMessage: () => (stderr) => `${expectedNote} not found in ${stderr}`, 151cb0ef41Sopenharmony_ci includeNote: true, 161cb0ef41Sopenharmony_ci}; 171cb0ef41Sopenharmony_ciconst mustNotIncludeMessage = { 181cb0ef41Sopenharmony_ci getMessage: () => (stderr) => `${expectedNote} must not be included in ${stderr}`, 191cb0ef41Sopenharmony_ci includeNote: false, 201cb0ef41Sopenharmony_ci}; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_cidescribe('ESM: Errors for unexpected exports', { concurrency: true }, () => { 231cb0ef41Sopenharmony_ci for ( 241cb0ef41Sopenharmony_ci const { errorNeedle, filePath, getMessage, includeNote } 251cb0ef41Sopenharmony_ci of [ 261cb0ef41Sopenharmony_ci { 271cb0ef41Sopenharmony_ci // name: '', 281cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-unexpected-export-1.cjs'), 291cb0ef41Sopenharmony_ci ...mustIncludeMessage, 301cb0ef41Sopenharmony_ci }, 311cb0ef41Sopenharmony_ci { 321cb0ef41Sopenharmony_ci // name: '', 331cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-unexpected-import-1.cjs'), 341cb0ef41Sopenharmony_ci ...mustIncludeMessage, 351cb0ef41Sopenharmony_ci }, 361cb0ef41Sopenharmony_ci { 371cb0ef41Sopenharmony_ci // name: '', 381cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-promiserej-import-2.cjs'), 391cb0ef41Sopenharmony_ci ...mustNotIncludeMessage, 401cb0ef41Sopenharmony_ci }, 411cb0ef41Sopenharmony_ci { 421cb0ef41Sopenharmony_ci // name: '', 431cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-unexpected-import-3.cjs'), 441cb0ef41Sopenharmony_ci ...mustIncludeMessage, 451cb0ef41Sopenharmony_ci }, 461cb0ef41Sopenharmony_ci { 471cb0ef41Sopenharmony_ci // name: '', 481cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-unexpected-import-4.cjs'), 491cb0ef41Sopenharmony_ci ...mustIncludeMessage, 501cb0ef41Sopenharmony_ci }, 511cb0ef41Sopenharmony_ci { 521cb0ef41Sopenharmony_ci // name: '', 531cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-unexpected-import-5.cjs'), 541cb0ef41Sopenharmony_ci ...mustNotIncludeMessage, 551cb0ef41Sopenharmony_ci }, 561cb0ef41Sopenharmony_ci { 571cb0ef41Sopenharmony_ci // name: '', 581cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-error-1.mjs'), 591cb0ef41Sopenharmony_ci ...mustNotIncludeMessage, 601cb0ef41Sopenharmony_ci errorNeedle: /Error: some error/, 611cb0ef41Sopenharmony_ci }, 621cb0ef41Sopenharmony_ci { 631cb0ef41Sopenharmony_ci // name: '', 641cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-error-2.mjs'), 651cb0ef41Sopenharmony_ci ...mustNotIncludeMessage, 661cb0ef41Sopenharmony_ci errorNeedle: /string/, 671cb0ef41Sopenharmony_ci }, 681cb0ef41Sopenharmony_ci { 691cb0ef41Sopenharmony_ci // name: '', 701cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-error-3.mjs'), 711cb0ef41Sopenharmony_ci ...mustNotIncludeMessage, 721cb0ef41Sopenharmony_ci errorNeedle: /null/, 731cb0ef41Sopenharmony_ci }, 741cb0ef41Sopenharmony_ci { 751cb0ef41Sopenharmony_ci // name: '', 761cb0ef41Sopenharmony_ci filePath: fixtures.path('/es-modules/es-note-error-4.mjs'), 771cb0ef41Sopenharmony_ci ...mustNotIncludeMessage, 781cb0ef41Sopenharmony_ci errorNeedle: /undefined/, 791cb0ef41Sopenharmony_ci }, 801cb0ef41Sopenharmony_ci ] 811cb0ef41Sopenharmony_ci ) { 821cb0ef41Sopenharmony_ci it(`should ${includeNote ? '' : 'NOT'} include note`, async () => { 831cb0ef41Sopenharmony_ci const { code, stderr } = await spawnPromisified(execPath, [filePath]); 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci assert.strictEqual(code, 1); 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci if (errorNeedle != null) assert.match(stderr, errorNeedle); 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci const shouldIncludeNote = stderr.includes(expectedNote); 901cb0ef41Sopenharmony_ci assert.ok( 911cb0ef41Sopenharmony_ci includeNote ? shouldIncludeNote : !shouldIncludeNote, 921cb0ef41Sopenharmony_ci `${filePath} ${getMessage(stderr)}`, 931cb0ef41Sopenharmony_ci ); 941cb0ef41Sopenharmony_ci }); 951cb0ef41Sopenharmony_ci } 961cb0ef41Sopenharmony_ci}); 97