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_cidescribe('default resolver', () => { 81cb0ef41Sopenharmony_ci // In these tests `byop` is an acronym for "bring your own protocol", and is the 91cb0ef41Sopenharmony_ci // protocol our byop-dummy-loader.mjs can load 101cb0ef41Sopenharmony_ci it('should accept foreign schemas without exception (e.g. byop://something/or-other)', async () => { 111cb0ef41Sopenharmony_ci const { code, stdout, stderr } = await spawnPromisified(execPath, [ 121cb0ef41Sopenharmony_ci '--no-warnings', 131cb0ef41Sopenharmony_ci '--experimental-loader', 141cb0ef41Sopenharmony_ci fixtures.fileURL('/es-module-loaders/byop-dummy-loader.mjs'), 151cb0ef41Sopenharmony_ci '--input-type=module', 161cb0ef41Sopenharmony_ci '--eval', 171cb0ef41Sopenharmony_ci "import 'byop://1/index.mjs'", 181cb0ef41Sopenharmony_ci ]); 191cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 201cb0ef41Sopenharmony_ci assert.strictEqual(stdout.trim(), 'index.mjs!'); 211cb0ef41Sopenharmony_ci assert.strictEqual(stderr, ''); 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci it('should resolve foreign schemas by doing regular url absolutization', async () => { 251cb0ef41Sopenharmony_ci const { code, stdout, stderr } = await spawnPromisified(execPath, [ 261cb0ef41Sopenharmony_ci '--no-warnings', 271cb0ef41Sopenharmony_ci '--experimental-loader', 281cb0ef41Sopenharmony_ci fixtures.fileURL('/es-module-loaders/byop-dummy-loader.mjs'), 291cb0ef41Sopenharmony_ci '--input-type=module', 301cb0ef41Sopenharmony_ci '--eval', 311cb0ef41Sopenharmony_ci "import 'byop://1/index2.mjs'", 321cb0ef41Sopenharmony_ci ]); 331cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 341cb0ef41Sopenharmony_ci assert.strictEqual(stdout.trim(), '42'); 351cb0ef41Sopenharmony_ci assert.strictEqual(stderr, ''); 361cb0ef41Sopenharmony_ci }); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci // In this test, `byoe` is an acronym for "bring your own extension" 391cb0ef41Sopenharmony_ci it('should accept foreign extensions without exception (e.g. ..//something.byoe)', async () => { 401cb0ef41Sopenharmony_ci const { code, stdout, stderr } = await spawnPromisified(execPath, [ 411cb0ef41Sopenharmony_ci '--no-warnings', 421cb0ef41Sopenharmony_ci '--experimental-loader', 431cb0ef41Sopenharmony_ci fixtures.fileURL('/es-module-loaders/byop-dummy-loader.mjs'), 441cb0ef41Sopenharmony_ci '--input-type=module', 451cb0ef41Sopenharmony_ci '--eval', 461cb0ef41Sopenharmony_ci "import 'byop://1/index.byoe'", 471cb0ef41Sopenharmony_ci ]); 481cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 491cb0ef41Sopenharmony_ci assert.strictEqual(stdout.trim(), 'index.byoe!'); 501cb0ef41Sopenharmony_ci assert.strictEqual(stderr, ''); 511cb0ef41Sopenharmony_ci }); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci it('should identify the parent module of an invalid URL host in import specifier', async () => { 541cb0ef41Sopenharmony_ci if (process.platform === 'win32') return; 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci const { code, stderr } = await spawnPromisified(execPath, [ 571cb0ef41Sopenharmony_ci '--no-warnings', 581cb0ef41Sopenharmony_ci fixtures.path('es-modules', 'invalid-posix-host.mjs'), 591cb0ef41Sopenharmony_ci ]); 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci assert.match(stderr, /ERR_INVALID_FILE_URL_HOST/); 621cb0ef41Sopenharmony_ci assert.match(stderr, /file:\/\/hmm\.js/); 631cb0ef41Sopenharmony_ci assert.match(stderr, /invalid-posix-host\.mjs/); 641cb0ef41Sopenharmony_ci assert.strictEqual(code, 1); 651cb0ef41Sopenharmony_ci }); 661cb0ef41Sopenharmony_ci}); 67