Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ assert.throws(
() => require('../fixtures/es-modules/loose.js'),
{
name: 'SyntaxError',
message: /Unexpected token 'export'/
message: /Unexpected token 'export'/,
});
2 changes: 1 addition & 1 deletion test/es-module/test-dynamic-import-script-lifetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ vm.runInThisContext(code, {
await m.link(() => {});
await m.evaluate();
return m;
}
},
});
12 changes: 6 additions & 6 deletions test/es-module/test-esm-cjs-named-error.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ await assert.rejects(async () => {
await import(`${fixtureBase}/single-quote.mjs`);
}, {
name: 'SyntaxError',
message: expectedRelative
message: expectedRelative,
}, 'should support relative specifiers with single quotes');

await assert.rejects(async () => {
await import(`${fixtureBase}/double-quote.mjs`);
}, {
name: 'SyntaxError',
message: expectedRelative
message: expectedRelative,
}, 'should support relative specifiers with double quotes');

await assert.rejects(async () => {
await import(`${fixtureBase}/renamed-import.mjs`);
}, {
name: 'SyntaxError',
message: expectedRenamed
message: expectedRenamed,
}, 'should correctly format named imports with renames');

await assert.rejects(async () => {
Expand All @@ -55,21 +55,21 @@ await assert.rejects(async () => {
await import(`${fixtureBase}/json-hack.mjs`);
}, {
name: 'SyntaxError',
message: expectedPackageHack
message: expectedPackageHack,
}, 'should respect recursive package.json for module type');

await assert.rejects(async () => {
await import(`${fixtureBase}/bare-import-single.mjs`);
}, {
name: 'SyntaxError',
message: expectedBare
message: expectedBare,
}, 'should support bare specifiers with single quotes');

await assert.rejects(async () => {
await import(`${fixtureBase}/bare-import-double.mjs`);
}, {
name: 'SyntaxError',
message: expectedBare
message: expectedBare,
}, 'should support bare specifiers with double quotes');

await assert.rejects(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-data-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function createBase64URL(mime, body) {
import('data:application/json;foo="test,",0',
{ with: { type: 'json' } }), {
name: 'SyntaxError',
message: /Unterminated string in JSON at position 3/
message: /Unterminated string in JSON at position 3/,
});
}
{
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-dns-promises.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ assert.throws(() => {
}, {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: `The argument 'address' is invalid. Received '${invalidAddress}'`
message: `The argument 'address' is invalid. Received '${invalidAddress}'`,
});
2 changes: 1 addition & 1 deletion test/es-module/test-esm-dynamic-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function expectOkNamespace(result) {
.then(common.mustCall((ns) => {
const expected = { default: true };
Object.defineProperty(expected, Symbol.toStringTag, {
value: 'Module'
value: 'Module',
});
Object.setPrototypeOf(expected, Object.getPrototypeOf(ns));
assert.deepStrictEqual(ns, expected);
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-import-meta.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ for (const descriptor of Object.values(descriptors)) {
assert.deepStrictEqual(descriptor, {
enumerable: true,
writable: true,
configurable: true
configurable: true,
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-invalid-format.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import assert from 'assert';
import('../fixtures/es-modules/test-esm-ok.mjs')
.then(assert.fail, expectsError({
code: 'ERR_UNKNOWN_MODULE_FORMAT',
message: /Unknown module format: esm/
message: /Unknown module format: esm/,
}))
.then(mustCall());
16 changes: 8 additions & 8 deletions test/es-module/test-esm-loader-mock.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import assert from 'node:assert/strict';
import { mock } from '../fixtures/es-module-loaders/mock.mjs';

mock('node:events', {
EventEmitter: 'This is mocked!'
EventEmitter: 'This is mocked!',
});

// This resolves to node:events
// It is intercepted by mock-loader and doesn't return the normal value
assert.deepStrictEqual(await import('events'), Object.defineProperty({
__proto__: null,
EventEmitter: 'This is mocked!'
EventEmitter: 'This is mocked!',
}, Symbol.toStringTag, {
enumerable: false,
value: 'Module'
value: 'Module',
}));

const mutator = mock('node:events', {
EventEmitter: 'This is mocked v2!'
EventEmitter: 'This is mocked v2!',
});

// It is intercepted by mock-loader and doesn't return the normal value.
Expand All @@ -26,17 +26,17 @@ const mutator = mock('node:events', {
const mockedV2 = await import('node:events');
assert.deepStrictEqual(mockedV2, Object.defineProperty({
__proto__: null,
EventEmitter: 'This is mocked v2!'
EventEmitter: 'This is mocked v2!',
}, Symbol.toStringTag, {
enumerable: false,
value: 'Module'
value: 'Module',
}));

mutator.EventEmitter = 'This is mocked v3!';
assert.deepStrictEqual(mockedV2, Object.defineProperty({
__proto__: null,
EventEmitter: 'This is mocked v3!'
EventEmitter: 'This is mocked v3!',
}, Symbol.toStringTag, {
enumerable: false,
value: 'Module'
value: 'Module',
}));
6 changes: 3 additions & 3 deletions test/es-module/test-esm-loader-modulemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl,
const errorObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "url" argument must be of type string/
message: /^The "url" argument must be of type string/,
};

[{}, [], true, 1].forEach((value) => {
Expand All @@ -73,7 +73,7 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl,
const errorObj = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "type" argument must be of type string/
message: /^The "type" argument must be of type string/,
};

[{}, [], true, 1].forEach((value) => {
Expand All @@ -91,7 +91,7 @@ const jsonModuleJob = new ModuleJob(loader, jsonModuleDataUrl,
assert.throws(() => moduleMap.set('', undefined, value), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /^The "job" argument must be an instance of ModuleJob/
message: /^The "job" argument must be an instance of ModuleJob/,
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-loader-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ require('../common');

const assert = require('assert');
const {
defaultResolve: resolve
defaultResolve: resolve,
} = require('internal/modules/esm/resolve');

assert.throws(
() => resolve('target'),
{
code: 'ERR_MODULE_NOT_FOUND',
name: 'Error',
message: /Cannot find package 'target'/
message: /Cannot find package 'target'/,
}
);
16 changes: 8 additions & 8 deletions test/es-module/test-esm-resolve-type.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (!isMainThread) {
import assert from 'assert';
import internalResolve from 'node:internal/modules/esm/resolve';
const {
defaultResolve: resolve
defaultResolve: resolve,
} = internalResolve;

const rel = (file) => tmpdir.resolve(file);
Expand Down Expand Up @@ -82,7 +82,7 @@ try {
createDir(subDir);
const pkgJsonContent = {
...(moduleType !== undefined) && { type: moduleType },
main: `subdir/mainfile.${moduleExtension}`
main: `subdir/mainfile.${moduleExtension}`,
};
fs.writeFileSync(pkg, JSON.stringify(pkgJsonContent));
fs.writeFileSync(script,
Expand Down Expand Up @@ -150,13 +150,13 @@ try {
'.': {
'require': './lib/index.js',
'import': './es/index.js',
'default': './lib/index.js'
'default': './lib/index.js',
},
'./package.json': './package.json',
}
},
};
const esmPkgJsonContent = {
type: 'module'
type: 'module',
};

fs.writeFileSync(pkg, JSON.stringify(mainPkgJsonContent));
Expand Down Expand Up @@ -220,13 +220,13 @@ try {
'.': {
'require': `./subdir/${mainRequireScript}${mainSuffix}`,
'import': `./subdir/${mainImportScript}${mainSuffix}`,
'default': `./subdir/${mainRequireScript}${mainSuffix}`
'default': `./subdir/${mainRequireScript}${mainSuffix}`,
},
'./package.json': './package.json',
}
},
};
const subdirPkgJsonContent = {
type: `${subdirPackageType}`
type: `${subdirPackageType}`,
};

fs.writeFileSync(pkg, JSON.stringify(mainPkgJsonContent));
Expand Down
12 changes: 6 additions & 6 deletions test/es-module/test-esm-symlink-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ const symlinks = [
source: 'extensionless-symlink-to-mjs-file',
target: fixtures.path('es-modules/mjs-file.mjs'),
prints: '.mjs file',
errorsWithPreserveSymlinksMain: false
errorsWithPreserveSymlinksMain: false,
}, {
source: 'extensionless-symlink-to-cjs-file',
target: fixtures.path('es-modules/cjs-file.cjs'),
prints: '.cjs file',
errorsWithPreserveSymlinksMain: false
errorsWithPreserveSymlinksMain: false,
}, {
source: 'extensionless-symlink-to-file-in-module-scope',
target: fixtures.path('es-modules/package-type-module/index.js'),
prints: 'package-type-module',
// The package scope of the symlinks' sources is commonjs, and this
// symlink's target is a .js file in a module scope, so when the scope
// is evaluated based on the source (commonjs) this esm file should error
errorsWithPreserveSymlinksMain: true
errorsWithPreserveSymlinksMain: true,
}, {
source: 'extensionless-symlink-to-file-in-explicit-commonjs-scope',
target: fixtures.path('es-modules/package-type-commonjs/index.js'),
prints: 'package-type-commonjs',
errorsWithPreserveSymlinksMain: false
errorsWithPreserveSymlinksMain: false,
}, {
source: 'extensionless-symlink-to-file-in-implicit-commonjs-scope',
target: fixtures.path('es-modules/package-without-type/index.js'),
prints: 'package-without-type',
errorsWithPreserveSymlinksMain: false
errorsWithPreserveSymlinksMain: false,
},
];

Expand All @@ -53,7 +53,7 @@ symlinks.forEach((symlink) => {
];
flags.forEach((nodeOptions) => {
const opts = {
env: Object.assign({}, process.env, { NODE_OPTIONS: nodeOptions })
env: Object.assign({}, process.env, { NODE_OPTIONS: nodeOptions }),
};
exec(process.execPath, [mainPath], opts, common.mustCall(
(err, stdout) => {
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-type-field-errors-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { describe, it } = require('node:test');
describe('Errors related to ESM type field', () => {
it('Should throw an error when loading CJS from a `type: "module"` package.', () => {
assert.throws(() => require('../fixtures/es-modules/package-type-module/index.js'), {
code: 'ERR_REQUIRE_ESM'
code: 'ERR_REQUIRE_ESM',
});
});
});
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-module-instances-warning.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ spawnSyncAndAssert(
stderr(output) {
assert.match(output, /ExperimentalWarning/);
assert.match(output, /Importing WebAssembly module instances/);
}
},
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ spawnSyncAndAssert(
stderr(output) {
assert.match(output, /Source phase import object is not defined for module/);
assert(output.includes(fileUrl));
}
},
}
);
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-top-level-execution.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ spawnSyncAndAssert(
{
stdout: '[Object: null prototype] { prop: \'hello world\' }',
stderr: '',
trim: true
trim: true,
}
);
2 changes: 1 addition & 1 deletion test/es-module/test-import-require-tla-twice.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ spawnSyncAndAssert(
stdout(output) {
const matches = output.matchAll(/e\.code === ERR_REQUIRE_ASYNC_MODULE true/g);
assert.strictEqual([...matches].length, 2);
}
},
}
);
4 changes: 2 additions & 2 deletions test/es-module/test-loaders-hidden-from-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ assert.throws(
require('internal/bootstrap/realm');
}, {
code: 'MODULE_NOT_FOUND',
message: /Cannot find module 'internal\/bootstrap\/realm'/
message: /Cannot find module 'internal\/bootstrap\/realm'/,
}
);

Expand All @@ -23,6 +23,6 @@ assert.throws(
require('owo');
}, {
code: 'MODULE_NOT_FOUND',
message: /Cannot find module 'owo'/
message: /Cannot find module 'owo'/,
}
);
2 changes: 1 addition & 1 deletion test/es-module/test-loaders-unknown-builtin-module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const unknownBuiltinModule = 'node:unknown-builtin-module';
import(unknownBuiltinModule)
.then(assert.fail, expectsError({
code: 'ERR_UNKNOWN_BUILTIN_MODULE',
message: `No such built-in module: ${unknownBuiltinModule}`
message: `No such built-in module: ${unknownBuiltinModule}`,
}))
.then(mustCall());
2 changes: 1 addition & 1 deletion test/es-module/test-require-as-esm-interop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const tests = {
'object': { a: 'cjs a', b: 'cjs b' },
'fauxesmdefault': { default: 'faux esm default' },
'fauxesmmixed': { default: 'faux esm default', a: 'faux esm a', b: 'faux esm b' },
'fauxesmnamed': { a: 'faux esm a', b: 'faux esm b' }
'fauxesmnamed': { a: 'faux esm a', b: 'faux esm b' },
};

// This test demonstrates interop between CJS and CJS represented as ESM
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-require-esm-from-imported-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spawnSyncAndAssert(
],
{
trim: true,
stdout: / default: { hello: 'world' }/
stdout: / default: { hello: 'world' }/,
}
);

Expand All @@ -31,6 +31,6 @@ spawnSyncAndAssert(
],
{
trim: true,
stdout: / default: { hello: 'world' }/
stdout: / default: { hello: 'world' }/,
}
);
2 changes: 1 addition & 1 deletion test/es-module/test-require-module-conditional-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { isModuleNamespaceObject } = require('util/types');
assert.throws(() => {
require('../fixtures/es-modules/exports-import-only/load.cjs');
}, {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED',
});

// If both are defined, "require" is used.
Expand Down
Loading
Loading