Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions test/es-module/test-esm-import-meta-resolve.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// Flags: --experimental-import-meta-resolve
import { spawnPromisified } from '../common/index.mjs';
import { fileURL as fixturesFileURL } from '../common/fixtures.mjs';
import assert from 'assert';
import { spawn } from 'child_process';
import { execPath } from 'process';

const dirname = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
const fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) + 1) + 'fixtures/';
const fixtures = `${fixturesFileURL()}/`;

assert.strictEqual(import.meta.resolve('./test-esm-import-meta.mjs'),
dirname + 'test-esm-import-meta.mjs');
new URL('./test-esm-import-meta.mjs', import.meta.url).href);
assert.strictEqual(import.meta.resolve('./notfound.mjs'), new URL('./notfound.mjs', import.meta.url).href);
assert.strictEqual(import.meta.resolve('./asset'), new URL('./asset', import.meta.url).href);
try {
assert.throws(() => {
import.meta.resolve('does-not-exist');
assert.fail();
} catch (e) {
assert.strictEqual(e.code, 'ERR_MODULE_NOT_FOUND');
}
}, {
code: 'ERR_MODULE_NOT_FOUND',
});
assert.strictEqual(
import.meta.resolve('../fixtures/empty-with-bom.txt'),
fixtures + 'empty-with-bom.txt');
Expand Down Expand Up @@ -60,11 +59,11 @@ await assert.rejects(import('data:text/javascript,export default import.meta.res
});

{
const cp = spawn(execPath, [
const { stdout } = await spawnPromisified(execPath, [
'--input-type=module',
'--eval', 'console.log(typeof import.meta.resolve)',
]);
assert.match((await cp.stdout.toArray()).toString(), /^function\r?\n$/);
assert.match(stdout, /^function\r?\n$/);
}

{
Expand All @@ -76,11 +75,11 @@ await assert.rejects(import('data:text/javascript,export default import.meta.res
}

{
const cp = spawn(execPath, [
const { stdout } = await spawnPromisified(execPath, [
'--input-type=module',
'--eval', 'import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"',
]);
assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/);
assert.match(stdout, /^node:os\r?\n$/);
}

{
Expand Down
27 changes: 10 additions & 17 deletions test/es-module/test-esm-pkgname.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { mustCall } from '../common/index.mjs';
import { strictEqual } from 'assert';
import '../common/index.mjs';
import assert from 'node:assert';

import { importFixture } from '../fixtures/pkgexports.mjs';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're making changes in tests, it would be nice if we could start adding comments that describe the expected tested behavior or make use of the node:test API and provide descriptive names for the tests.


importFixture('as%2Ff').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));

importFixture('as%5Cf').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));

importFixture('as\\df').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));

importFixture('@as@df').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_INVALID_MODULE_SPECIFIER');
}));
await Promise.all([
'as%2Ff',
'as%5Cf',
'as\\df',
'@as@df',
].map((specifier) => assert.rejects(importFixture(specifier), {
code: 'ERR_INVALID_MODULE_SPECIFIER',
})));
Loading