Skip to content

Commit 0457bfe

Browse files
authored
test: forbid use of named imports for fixtures
PR-URL: #61228 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
1 parent c6a56b4 commit 0457bfe

File tree

68 files changed

+164
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+164
-141
lines changed

test/addons/openssl-providers/test-default-only-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const { path: fixture } = require('../../common/fixtures');
4+
const fixtures = require('../../common/fixtures');
55
const providers = require('./providers.cjs');
66

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

1111
if (!process.execArgv.includes(option)) {
1212
const cp = fork(__filename, { execArgv: [option] });

test/addons/openssl-providers/test-legacy-provider-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const { path: fixture } = require('../../common/fixtures');
4+
const fixtures = require('../../common/fixtures');
55
const providers = require('./providers.cjs');
66

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

1111
if (!process.execArgv.includes(option)) {
1212
const cp = fork(__filename, { execArgv: [option] });

test/addons/openssl-providers/test-legacy-provider-inactive-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const { path: fixture } = require('../../common/fixtures');
4+
const fixtures = require('../../common/fixtures');
55
const providers = require('./providers.cjs');
66

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

1111
if (!process.execArgv.includes(option)) {
1212
const cp = fork(__filename, { execArgv: [option] });

test/common/fixtures.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ const { pathToFileURL } = require('url');
77
const fixturesDir = path.join(__dirname, '..', 'fixtures');
88

99
function fixturesPath(...args) {
10-
return path.join(fixturesDir, ...args);
10+
args.unshift(fixturesDir);
11+
return Reflect.apply(path.join, this, args);
1112
}
1213

1314
function fixturesFileURL(...args) {
14-
return pathToFileURL(fixturesPath(...args));
15+
return pathToFileURL(Reflect.apply(fixturesPath, this, args));
1516
}
1617

1718
function readFixtureSync(args, enc) {
1819
if (Array.isArray(args))
19-
return fs.readFileSync(fixturesPath(...args), enc);
20+
return fs.readFileSync(Reflect.apply(fixturesPath, this, args), enc);
2021
return fs.readFileSync(fixturesPath(args), enc);
2122
}
2223

test/es-module/test-esm-experimental-warnings.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnPromisified } from '../common/index.mjs';
2-
import { fileURL } from '../common/fixtures.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
33
import assert from 'node:assert';
44
import { execPath } from 'node:process';
55
import { describe, it } from 'node:test';
@@ -10,7 +10,7 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE
1010
const { code, signal, stderr } = await spawnPromisified(execPath, [
1111
'--input-type=module',
1212
'--eval',
13-
`import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
13+
`import ${JSON.stringify(fixtures.fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
1414
]);
1515

1616
assert.doesNotMatch(
@@ -28,7 +28,7 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE
2828
[
2929
/`--experimental-loader` may be removed in the future/,
3030
'--experimental-loader',
31-
fileURL('es-module-loaders', 'hooks-custom.mjs'),
31+
fixtures.fileURL('es-module-loaders', 'hooks-custom.mjs'),
3232
],
3333
]
3434
) {
@@ -37,7 +37,7 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TE
3737
...args,
3838
'--input-type=module',
3939
'--eval',
40-
`import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
40+
`import ${JSON.stringify(fixtures.fileURL('es-module-loaders', 'module-named-exports.mjs'))}`,
4141
]);
4242

4343
assert.match(stderr, /ExperimentalWarning/);

test/es-module/test-esm-import-meta-main-eval.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnPromisified } from '../common/index.mjs';
2-
import * as fixtures from '../common/fixtures.js';
2+
import * as fixtures from '../common/fixtures.mjs';
33
import assert from 'node:assert/strict';
44
import { describe, it } from 'node:test';
55

test/es-module/test-esm-import-meta-resolve.mjs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Flags: --experimental-import-meta-resolve
22
import { spawnPromisified } from '../common/index.mjs';
3-
import { fileURL as fixturesFileURL } from '../common/fixtures.mjs';
3+
import * as fixtures from '../common/fixtures.mjs';
44
import assert from 'assert';
55
import { spawn } from 'child_process';
66
import { execPath } from 'process';
77

8-
const fixtures = `${fixturesFileURL()}/`;
8+
const fixturesDir = `${fixtures.fileURL()}/`;
99

1010
assert.strictEqual(import.meta.resolve('./test-esm-import-meta.mjs'),
1111
new URL('./test-esm-import-meta.mjs', import.meta.url).href);
@@ -18,23 +18,23 @@ assert.throws(() => {
1818
});
1919
assert.strictEqual(
2020
import.meta.resolve('../fixtures/empty-with-bom.txt'),
21-
fixtures + 'empty-with-bom.txt');
22-
assert.strictEqual(import.meta.resolve('../fixtures/'), fixtures);
21+
fixturesDir + 'empty-with-bom.txt');
22+
assert.strictEqual(import.meta.resolve('../fixtures/'), fixturesDir);
2323
assert.strictEqual(
2424
import.meta.resolve('../fixtures/', import.meta.url),
25-
fixtures);
25+
fixturesDir);
2626
assert.strictEqual(
2727
import.meta.resolve('../fixtures/', new URL(import.meta.url)),
28-
fixtures);
28+
fixturesDir);
2929
[[], {}, Symbol(), 0, 1, 1n, 1.1, () => {}, true, false].forEach((arg) =>
3030
assert.throws(() => import.meta.resolve('../fixtures/', arg), {
3131
code: 'ERR_INVALID_ARG_TYPE',
3232
})
3333
);
3434
assert.strictEqual(import.meta.resolve('http://some-absolute/url'), 'http://some-absolute/url');
3535
assert.strictEqual(import.meta.resolve('some://weird/protocol'), 'some://weird/protocol');
36-
assert.strictEqual(import.meta.resolve('baz/', fixtures),
37-
fixtures + 'node_modules/baz/');
36+
assert.strictEqual(import.meta.resolve('baz/', fixturesDir),
37+
fixturesDir + 'node_modules/baz/');
3838
assert.deepStrictEqual(
3939
{ ...await import('data:text/javascript,export default import.meta.resolve("http://some-absolute/url")') },
4040
{ default: 'http://some-absolute/url' },
@@ -44,8 +44,8 @@ assert.deepStrictEqual(
4444
{ default: 'some://weird/protocol' },
4545
);
4646
assert.deepStrictEqual(
47-
{ ...await import(`data:text/javascript,export default import.meta.resolve("baz/", ${encodeURIComponent(JSON.stringify(fixtures))})`) },
48-
{ default: fixtures + 'node_modules/baz/' },
47+
{ ...await import(`data:text/javascript,export default import.meta.resolve("baz/", ${encodeURIComponent(JSON.stringify(fixturesDir))})`) },
48+
{ default: fixturesDir + 'node_modules/baz/' },
4949
);
5050
assert.deepStrictEqual(
5151
{ ...await import('data:text/javascript,export default import.meta.resolve("fs")') },

test/es-module/test-esm-loader-programmatically.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnPromisified } from '../common/index.mjs';
2-
import * as fixtures from '../common/fixtures.js';
2+
import * as fixtures from '../common/fixtures.mjs';
33
import assert from 'node:assert';
44
import { execPath } from 'node:process';
55
import { describe, it } from 'node:test';

test/es-module/test-esm-loader-thenable.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnPromisified } from '../common/index.mjs';
2-
import { fileURL, path } from '../common/fixtures.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
33
import assert from 'assert';
44
import { execPath } from 'node:process';
55
import { describe, it } from 'node:test';
@@ -9,8 +9,8 @@ describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL
99
it('should behave as a normal promise resolution', async () => {
1010
const { code, stderr } = await spawnPromisified(execPath, [
1111
'--experimental-loader',
12-
fileURL('es-module-loaders', 'thenable-load-hook.mjs').href,
13-
path('es-modules', 'test-esm-ok.mjs'),
12+
fixtures.fileURL('es-module-loaders', 'thenable-load-hook.mjs').href,
13+
fixtures.path('es-modules', 'test-esm-ok.mjs'),
1414
]);
1515

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

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

3939
assert.notStrictEqual(code, 0);

test/es-module/test-esm-loader-with-syntax-error.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnPromisified } from '../common/index.mjs';
2-
import { fileURL, path } from '../common/fixtures.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
33
import assert from 'node:assert';
44
import { execPath } from 'node:process';
55
import { describe, it } from 'node:test';
@@ -9,8 +9,8 @@ describe('ESM: loader with syntax error', { concurrency: !process.env.TEST_PARAL
99
it('should crash the node process', async () => {
1010
const { code, stderr } = await spawnPromisified(execPath, [
1111
'--experimental-loader',
12-
fileURL('es-module-loaders', 'syntax-error.mjs').href,
13-
path('print-error-message.js'),
12+
fixtures.fileURL('es-module-loaders', 'syntax-error.mjs').href,
13+
fixtures.path('print-error-message.js'),
1414
]);
1515

1616
assert.match(stderr, /SyntaxError/);

0 commit comments

Comments
 (0)