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) + 7 1) + 'fixtures/'; 8 9(async () => { 10 assert.strictEqual(await import.meta.resolve('./test-esm-import-meta.mjs'), 11 dirname + 'test-esm-import-meta.mjs'); 12 try { 13 await import.meta.resolve('./notfound.mjs'); 14 assert.fail(); 15 } catch (e) { 16 assert.strictEqual(e.code, 'ERR_MODULE_NOT_FOUND'); 17 } 18 assert.strictEqual( 19 await import.meta.resolve('../fixtures/empty-with-bom.txt'), 20 fixtures + 'empty-with-bom.txt'); 21 assert.strictEqual(await import.meta.resolve('../fixtures/'), fixtures); 22 assert.strictEqual( 23 await import.meta.resolve('../fixtures/', import.meta.url), 24 fixtures); 25 assert.strictEqual( 26 await import.meta.resolve('../fixtures/', new URL(import.meta.url)), 27 fixtures); 28 await Promise.all( 29 [[], {}, Symbol(), 0, 1, 1n, 1.1, () => {}, true, false].map((arg) => 30 assert.rejects(import.meta.resolve('../fixtures/', arg), { 31 code: 'ERR_INVALID_ARG_TYPE', 32 }) 33 ) 34 ); 35 assert.strictEqual(await import.meta.resolve('baz/', fixtures), 36 fixtures + 'node_modules/baz/'); 37})().then(mustCall()); 38