11cb0ef41Sopenharmony_ci// Flags: --experimental-import-meta-resolve 21cb0ef41Sopenharmony_ciimport '../common/index.mjs'; 31cb0ef41Sopenharmony_ciimport assert from 'assert'; 41cb0ef41Sopenharmony_ciimport { spawn } from 'child_process'; 51cb0ef41Sopenharmony_ciimport { execPath } from 'process'; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst dirname = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1); 81cb0ef41Sopenharmony_ciconst fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) + 1) + 'fixtures/'; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciassert.strictEqual(import.meta.resolve('./test-esm-import-meta.mjs'), 111cb0ef41Sopenharmony_ci dirname + 'test-esm-import-meta.mjs'); 121cb0ef41Sopenharmony_ciassert.strictEqual(import.meta.resolve('./notfound.mjs'), new URL('./notfound.mjs', import.meta.url).href); 131cb0ef41Sopenharmony_ciassert.strictEqual(import.meta.resolve('./asset'), new URL('./asset', import.meta.url).href); 141cb0ef41Sopenharmony_citry { 151cb0ef41Sopenharmony_ci import.meta.resolve('does-not-exist'); 161cb0ef41Sopenharmony_ci assert.fail(); 171cb0ef41Sopenharmony_ci} catch (e) { 181cb0ef41Sopenharmony_ci assert.strictEqual(e.code, 'ERR_MODULE_NOT_FOUND'); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ciassert.strictEqual( 211cb0ef41Sopenharmony_ci import.meta.resolve('../fixtures/empty-with-bom.txt'), 221cb0ef41Sopenharmony_ci fixtures + 'empty-with-bom.txt'); 231cb0ef41Sopenharmony_ciassert.strictEqual(import.meta.resolve('../fixtures/'), fixtures); 241cb0ef41Sopenharmony_ciassert.strictEqual( 251cb0ef41Sopenharmony_ci import.meta.resolve('../fixtures/', import.meta.url), 261cb0ef41Sopenharmony_ci fixtures); 271cb0ef41Sopenharmony_ciassert.strictEqual( 281cb0ef41Sopenharmony_ci import.meta.resolve('../fixtures/', new URL(import.meta.url)), 291cb0ef41Sopenharmony_ci fixtures); 301cb0ef41Sopenharmony_ci[[], {}, Symbol(), 0, 1, 1n, 1.1, () => {}, true, false].map((arg) => 311cb0ef41Sopenharmony_ci assert.throws(() => import.meta.resolve('../fixtures/', arg), { 321cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 331cb0ef41Sopenharmony_ci }) 341cb0ef41Sopenharmony_ci); 351cb0ef41Sopenharmony_ciassert.strictEqual(import.meta.resolve('baz/', fixtures), 361cb0ef41Sopenharmony_ci fixtures + 'node_modules/baz/'); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci{ 391cb0ef41Sopenharmony_ci const cp = spawn(execPath, [ 401cb0ef41Sopenharmony_ci '--input-type=module', 411cb0ef41Sopenharmony_ci '--eval', 'console.log(typeof import.meta.resolve)', 421cb0ef41Sopenharmony_ci ]); 431cb0ef41Sopenharmony_ci assert.match((await cp.stdout.toArray()).toString(), /^function\r?\n$/); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci{ 471cb0ef41Sopenharmony_ci const cp = spawn(execPath, [ 481cb0ef41Sopenharmony_ci '--input-type=module', 491cb0ef41Sopenharmony_ci ]); 501cb0ef41Sopenharmony_ci cp.stdin.end('console.log(typeof import.meta.resolve)'); 511cb0ef41Sopenharmony_ci assert.match((await cp.stdout.toArray()).toString(), /^function\r?\n$/); 521cb0ef41Sopenharmony_ci} 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci{ 551cb0ef41Sopenharmony_ci const cp = spawn(execPath, [ 561cb0ef41Sopenharmony_ci '--input-type=module', 571cb0ef41Sopenharmony_ci '--eval', 'import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"', 581cb0ef41Sopenharmony_ci ]); 591cb0ef41Sopenharmony_ci assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/); 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci{ 631cb0ef41Sopenharmony_ci const cp = spawn(execPath, [ 641cb0ef41Sopenharmony_ci '--input-type=module', 651cb0ef41Sopenharmony_ci ]); 661cb0ef41Sopenharmony_ci cp.stdin.end('import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"'); 671cb0ef41Sopenharmony_ci assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/); 681cb0ef41Sopenharmony_ci} 69