1// Flags: --experimental-import-meta-resolve 2import { mustCall } from '../common/index.mjs'; 3import assert from 'assert'; 4 5const dirname = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1); 6const fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) + 1) + 'fixtures/'; 7 8(async () => { 9 assert.strictEqual(await import.meta.resolve('./test-esm-import-meta.mjs'), 10 dirname + 'test-esm-import-meta.mjs'); 11 try { 12 await import.meta.resolve('./notfound.mjs'); 13 assert.fail(); 14 } catch (e) { 15 assert.strictEqual(e.code, 'ERR_MODULE_NOT_FOUND'); 16 } 17 assert.strictEqual( 18 await import.meta.resolve('../fixtures/empty-with-bom.txt'), 19 fixtures + 'empty-with-bom.txt'); 20 assert.strictEqual(await import.meta.resolve('../fixtures/'), fixtures); 21 assert.strictEqual( 22 await import.meta.resolve('../fixtures/', import.meta.url), 23 fixtures); 24 assert.strictEqual( 25 await import.meta.resolve('../fixtures/', new URL(import.meta.url)), 26 fixtures); 27 await Promise.all( 28 [[], {}, Symbol(), 0, 1, 1n, 1.1, () => {}, true, false].map((arg) => 29 assert.rejects(import.meta.resolve('../fixtures/', arg), { 30 code: 'ERR_INVALID_ARG_TYPE', 31 }) 32 ) 33 ); 34 assert.strictEqual(await import.meta.resolve('http://some-absolute/url'), 'http://some-absolute/url'); 35 assert.strictEqual(await import.meta.resolve('some://weird/protocol'), 'some://weird/protocol'); 36 assert.strictEqual(await import.meta.resolve('baz/', fixtures), 37 fixtures + 'node_modules/baz/'); 38})().then(mustCall()); 39