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
4 changes: 2 additions & 2 deletions test/addons/openssl-providers/test-default-only-config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const common = require('../../common');
const { path: fixture } = require('../../common/fixtures');
const fixtures = require('../../common/fixtures');
const providers = require('./providers.cjs');

const assert = require('node:assert');
const { fork } = require('node:child_process');
const option = `--openssl-config=${fixture('openssl3-conf', 'default_only.cnf')}`;
const option = `--openssl-config=${fixtures.path('openssl3-conf', 'default_only.cnf')}`;

if (!process.execArgv.includes(option)) {
const cp = fork(__filename, { execArgv: [option] });
Expand Down
4 changes: 2 additions & 2 deletions test/addons/openssl-providers/test-legacy-provider-config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const common = require('../../common');
const { path: fixture } = require('../../common/fixtures');
const fixtures = require('../../common/fixtures');
const providers = require('./providers.cjs');

const assert = require('node:assert');
const { fork } = require('node:child_process');
const option = `--openssl-config=${fixture('openssl3-conf', 'legacy_provider_enabled.cnf')}`;
const option = `--openssl-config=${fixtures.path('openssl3-conf', 'legacy_provider_enabled.cnf')}`;

if (!process.execArgv.includes(option)) {
const cp = fork(__filename, { execArgv: [option] });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const common = require('../../common');
const { path: fixture } = require('../../common/fixtures');
const fixtures = require('../../common/fixtures');
const providers = require('./providers.cjs');

const assert = require('node:assert');
const { fork } = require('node:child_process');
const option = `--openssl-config=${fixture('openssl3-conf', 'legacy_provider_inactive.cnf')}`;
const option = `--openssl-config=${fixtures.path('openssl3-conf', 'legacy_provider_inactive.cnf')}`;

if (!process.execArgv.includes(option)) {
const cp = fork(__filename, { execArgv: [option] });
Expand Down
7 changes: 4 additions & 3 deletions test/common/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ const { pathToFileURL } = require('url');
const fixturesDir = path.join(__dirname, '..', 'fixtures');

function fixturesPath(...args) {
return path.join(fixturesDir, ...args);
args.unshift(fixturesDir);
return Reflect.apply(path.join, this, args);
}

function fixturesFileURL(...args) {
return pathToFileURL(fixturesPath(...args));
return pathToFileURL(Reflect.apply(fixturesPath, this, args));
}

function readFixtureSync(args, enc) {
if (Array.isArray(args))
return fs.readFileSync(fixturesPath(...args), enc);
return fs.readFileSync(Reflect.apply(fixturesPath, this, args), enc);
return fs.readFileSync(fixturesPath(args), enc);
}

Expand Down
8 changes: 4 additions & 4 deletions test/es-module/test-esm-experimental-warnings.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import { fileURL } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
Expand All @@ -10,7 +10,7 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--input-type=module',
'--eval',
`import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
`import ${JSON.stringify(fixtures.fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
]);

assert.doesNotMatch(
Expand All @@ -28,7 +28,7 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE
[
/`--experimental-loader` may be removed in the future/,
'--experimental-loader',
fileURL('es-module-loaders', 'hooks-custom.mjs'),
fixtures.fileURL('es-module-loaders', 'hooks-custom.mjs'),
],
]
) {
Expand All @@ -37,7 +37,7 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE
...args,
'--input-type=module',
'--eval',
`import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
`import ${JSON.stringify(fixtures.fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
]);

assert.match(stderr, /ExperimentalWarning/);
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-import-meta-main-eval.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

Expand Down
20 changes: 10 additions & 10 deletions test/es-module/test-esm-import-meta-resolve.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Flags: --experimental-import-meta-resolve
import { spawnPromisified } from '../common/index.mjs';
import { fileURL as fixturesFileURL } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'assert';
import { spawn } from 'child_process';
import { execPath } from 'process';

const fixtures = `${fixturesFileURL()}/`;
const fixturesDir = `${fixtures.fileURL()}/`;

assert.strictEqual(import.meta.resolve('./test-esm-import-meta.mjs'),
new URL('./test-esm-import-meta.mjs', import.meta.url).href);
Expand All @@ -18,23 +18,23 @@ assert.throws(() => {
});
assert.strictEqual(
import.meta.resolve('../fixtures/empty-with-bom.txt'),
fixtures + 'empty-with-bom.txt');
assert.strictEqual(import.meta.resolve('../fixtures/'), fixtures);
fixturesDir + 'empty-with-bom.txt');
assert.strictEqual(import.meta.resolve('../fixtures/'), fixturesDir);
assert.strictEqual(
import.meta.resolve('../fixtures/', import.meta.url),
fixtures);
fixturesDir);
assert.strictEqual(
import.meta.resolve('../fixtures/', new URL(import.meta.url)),
fixtures);
fixturesDir);
[[], {}, Symbol(), 0, 1, 1n, 1.1, () => {}, true, false].forEach((arg) =>
assert.throws(() => import.meta.resolve('../fixtures/', arg), {
code: 'ERR_INVALID_ARG_TYPE',
})
);
assert.strictEqual(import.meta.resolve('http://some-absolute/url'), 'http://some-absolute/url');
assert.strictEqual(import.meta.resolve('some://weird/protocol'), 'some://weird/protocol');
assert.strictEqual(import.meta.resolve('baz/', fixtures),
fixtures + 'node_modules/baz/');
assert.strictEqual(import.meta.resolve('baz/', fixturesDir),
fixturesDir + 'node_modules/baz/');
assert.deepStrictEqual(
{ ...await import('data:text/javascript,export default import.meta.resolve("http://some-absolute/url")') },
{ default: 'http://some-absolute/url' },
Expand All @@ -44,8 +44,8 @@ assert.deepStrictEqual(
{ default: 'some://weird/protocol' },
);
assert.deepStrictEqual(
{ ...await import(`data:text/javascript,export default import.meta.resolve("baz/", ${encodeURIComponent(JSON.stringify(fixtures))})`) },
{ default: fixtures + 'node_modules/baz/' },
{ ...await import(`data:text/javascript,export default import.meta.resolve("baz/", ${encodeURIComponent(JSON.stringify(fixturesDir))})`) },
{ default: fixturesDir + 'node_modules/baz/' },
);
assert.deepStrictEqual(
{ ...await import('data:text/javascript,export default import.meta.resolve("fs")') },
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-programmatically.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
Expand Down
14 changes: 7 additions & 7 deletions test/es-module/test-esm-loader-thenable.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import { fileURL, path } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
Expand All @@ -9,8 +9,8 @@ describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL
it('should behave as a normal promise resolution', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--experimental-loader',
fileURL('es-module-loaders', 'thenable-load-hook.mjs').href,
path('es-modules', 'test-esm-ok.mjs'),
fixtures.fileURL('es-module-loaders', 'thenable-load-hook.mjs').href,
fixtures.path('es-modules', 'test-esm-ok.mjs'),
]);

assert.strictEqual(code, 0);
Expand All @@ -20,8 +20,8 @@ describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL
it('should crash the node process rejection with an error', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--experimental-loader',
fileURL('es-module-loaders', 'thenable-load-hook-rejected.mjs').href,
path('es-modules', 'test-esm-ok.mjs'),
fixtures.fileURL('es-module-loaders', 'thenable-load-hook-rejected.mjs').href,
fixtures.path('es-modules', 'test-esm-ok.mjs'),
]);

assert.notStrictEqual(code, 0);
Expand All @@ -32,8 +32,8 @@ describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL
it('should just reject without an error (but NOT crash the node process)', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--experimental-loader',
fileURL('es-module-loaders', 'thenable-load-hook-rejected-no-arguments.mjs').href,
path('es-modules', 'test-esm-ok.mjs'),
fixtures.fileURL('es-module-loaders', 'thenable-load-hook-rejected-no-arguments.mjs').href,
fixtures.path('es-modules', 'test-esm-ok.mjs'),
]);

assert.notStrictEqual(code, 0);
Expand Down
6 changes: 3 additions & 3 deletions test/es-module/test-esm-loader-with-syntax-error.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import { fileURL, path } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
Expand All @@ -9,8 +9,8 @@ describe('ESM: loader with syntax error', { concurrency: !process.env.TEST_PARAL
it('should crash the node process', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--experimental-loader',
fileURL('es-module-loaders', 'syntax-error.mjs').href,
path('print-error-message.js'),
fixtures.fileURL('es-module-loaders', 'syntax-error.mjs').href,
fixtures.path('print-error-message.js'),
]);

assert.match(stderr, /SyntaxError/);
Expand Down
6 changes: 3 additions & 3 deletions test/es-module/test-esm-module-not-found-commonjs-hint.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { spawnPromisified } from '../common/index.mjs';
import { fixturesDir, fileURL as fixtureSubDir } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: module not found hint', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (
const { input, expected, cwd = fixturesDir }
const { input, expected, cwd = fixtures.fixturesDir }
of [
{
input: 'import "./print-error-message"',
Expand All @@ -23,7 +23,7 @@ describe('ESM: module not found hint', { concurrency: !process.env.TEST_PARALLEL
input: 'import "../folder%25with percentage#/index.js"',
// Did you mean to import "../es-modules/folder%2525with%20percentage%23/index.js"?
expected: / "\.\.\/folder%2525with%20percentage%23\/index\.js"\?/,
cwd: fixtureSubDir('es-modules/tla/'),
cwd: fixtures.fileURL('es-modules/tla/'),
},
{
input: 'import obj from "some_module/obj"',
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-non-js.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import { fileURL } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
Expand All @@ -10,7 +10,7 @@ describe('ESM: non-js extensions fail', { concurrency: !process.env.TEST_PARALLE
const { code, stderr, signal } = await spawnPromisified(execPath, [
'--input-type=module',
'--eval',
`import ${JSON.stringify(fileURL('es-modules', 'file.unknown'))}`,
`import ${JSON.stringify(fixtures.fileURL('es-modules', 'file.unknown'))}`,
]);

assert.match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-nowarn-exports.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import { path } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
Expand All @@ -9,7 +9,7 @@ describe('ESM: experiemental warning for import.meta.resolve', { concurrency: !p
it('should not warn when caught', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--experimental-import-meta-resolve',
path('es-modules/import-resolve-exports.mjs'),
fixtures.path('es-modules/import-resolve-exports.mjs'),
]);

assert.strictEqual(stderr, '');
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-syntax-error.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnPromisified } from '../common/index.mjs';
import { path } from '../common/fixtures.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
Expand All @@ -8,7 +8,7 @@ import { describe, it } from 'node:test';
describe('ESM: importing a module with syntax error(s)', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should throw', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
path('es-module-loaders', 'syntax-error.mjs'),
fixtures.path('es-module-loaders', 'syntax-error.mjs'),
]);
assert.match(stderr, /SyntaxError:/);
assert.notStrictEqual(code, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-escape-import-names.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test that import names are properly escaped
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-globals-all-types.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test that all WebAssembly global types are properly handled
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-js-string-builtins.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test that js-string builtins are supported
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-load-exports.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test that WASM modules can load and export functions correctly
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
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 @@ -3,7 +3,7 @@ import '../common/index.mjs';
import assert from 'node:assert';

import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-no-code-injection.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test that code injection through export names is not allowed
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-non-identifier-exports.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test that WASM modules can have non-identifier export names
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-reject-wasm-export-names.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test WASM module with invalid export name starting with 'wasm:'
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-wasm-reject-wasm-import-names.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test WASM module with invalid import name starting with 'wasm:'
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test WASM module with invalid export name starting with 'wasm-js:'
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test WASM module with invalid import module name starting with 'wasm-js:'
import '../common/index.mjs';
import { spawnSyncAndAssert } from '../common/child_process.js';
import * as fixtures from '../common/fixtures.js';
import * as fixtures from '../common/fixtures.mjs';

spawnSyncAndAssert(
process.execPath,
Expand Down
Loading
Loading