Skip to content

Commit 510649f

Browse files
committed
test: use unusual chars in the path to ensure our tests are robust
PR-URL: #48409 Reviewed-By: Jacob Smith <[email protected]>
1 parent c102328 commit 510649f

12 files changed

+82
-39
lines changed

.github/workflows/test-linux.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4141
with:
4242
persist-credentials: false
43+
path: node
4344
- name: Set up Python ${{ env.PYTHON_VERSION }}
4445
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
4546
with:
@@ -51,6 +52,13 @@ jobs:
5152
- name: Environment Information
5253
run: npx envinfo
5354
- name: Build
54-
run: make build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn"
55+
run: make -C node build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn"
5556
- name: Test
56-
run: make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9"
57+
run: make -C node run-ci -j4 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9"
58+
- name: Re-run test in a folder whose name contains unusual chars
59+
run: |
60+
mv node "$DIR"
61+
cd "$DIR"
62+
./tools/test.py --flaky-tests keep_retrying -p actions -j 4
63+
env:
64+
DIR: dir%20with $unusual"chars?'åß∂ƒ©∆¬…`

.github/workflows/test-macos.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5252
with:
5353
persist-credentials: false
54+
path: node
5455
- name: Set up Python ${{ env.PYTHON_VERSION }}
5556
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
5657
with:
@@ -68,7 +69,7 @@ jobs:
6869
# happen anymore running this step here first, that's also useful
6970
# information.)
7071
- name: tools/doc/node_modules workaround
71-
run: make tools/doc/node_modules
72+
run: make -C node tools/doc/node_modules
7273
# This is needed due to https://github.com/nodejs/build/issues/3878
7374
- name: Cleanup
7475
run: |
@@ -84,8 +85,15 @@ jobs:
8485
df -h
8586
echo "::endgroup::"
8687
- name: Build
87-
run: make build-ci -j$(getconf _NPROCESSORS_ONLN) V=1 CONFIG_FLAGS="--error-on-warn"
88+
run: make -C node build-ci -j$(getconf _NPROCESSORS_ONLN) V=1 CONFIG_FLAGS="--error-on-warn"
8889
- name: Free Space After Build
8990
run: df -h
9091
- name: Test
91-
run: make run-ci -j$(getconf _NPROCESSORS_ONLN) V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9"
92+
run: make -C node run-ci -j$(getconf _NPROCESSORS_ONLN) V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9"
93+
- name: Re-run test in a folder whose name contains unusual chars
94+
run: |
95+
mv node "$DIR"
96+
cd "$DIR"
97+
./tools/test.py --flaky-tests keep_retrying -p actions -j 4
98+
env:
99+
DIR: dir%20with $unusual"chars?'åß∂ƒ©∆¬…`

test/common/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,15 @@ const common = {
11351135
get checkoutEOL() {
11361136
return fs.readFileSync(__filename).includes('\r\n') ? '\r\n' : '\n';
11371137
},
1138+
1139+
get isInsideDirWithUnusualChars() {
1140+
return __dirname.includes('%') ||
1141+
(!isWindows && __dirname.includes('\\')) ||
1142+
__dirname.includes('$') ||
1143+
__dirname.includes('\n') ||
1144+
__dirname.includes('\r') ||
1145+
__dirname.includes('\t');
1146+
},
11381147
};
11391148

11401149
const validProperties = new Set(Object.keys(common));

test/common/index.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626
isDumbTerminal,
2727
isFreeBSD,
2828
isIBMi,
29+
isInsideDirWithUnusualChars,
2930
isLinux,
3031
isLinuxPPCBE,
3132
isMainThread,
@@ -81,6 +82,7 @@ export {
8182
isDumbTerminal,
8283
isFreeBSD,
8384
isIBMi,
85+
isInsideDirWithUnusualChars,
8486
isLinux,
8587
isLinuxPPCBE,
8688
isMainThread,

test/es-module/test-esm-invalid-pjson.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('ESM: Package.json', { concurrency: !process.env.TEST_PARALLEL }, () =>
1919
assert.ok(
2020
stderr.includes(
2121
`Invalid package config ${path.toNamespacedPath(invalidJson)} while importing "invalid-pjson" from ${entry}.`
22+
) || stderr.includes(
23+
`Invalid package config ${path.toNamespacedPath(invalidJson)} while importing "invalid-pjson" from ${path.toNamespacedPath(entry)}.`
2224
),
2325
stderr
2426
);

test/fixtures/snapshot/child-process-sync.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const {
88
function spawn() {
99
const { spawnSync, execFileSync, execSync } = require('child_process');
1010
spawnSync(process.execPath, [ __filename, 'spawnSync' ], { stdio: 'inherit' });
11-
execSync(`"${process.execPath}" "${__filename}" "execSync"`, { stdio: 'inherit' });
11+
if (!process.env.DIRNAME_CONTAINS_SHELL_UNSAFE_CHARS)
12+
execSync(`"${process.execPath}" "${__filename}" "execSync"`, { stdio: 'inherit' });
1213
execFileSync(process.execPath, [ __filename, 'execFileSync' ], { stdio: 'inherit' });
1314
}
1415

test/parallel/test-fs-cp.mjs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mustCall, mustNotMutateObjectDeep } from '../common/index.mjs';
1+
import { mustCall, mustNotMutateObjectDeep, isInsideDirWithUnusualChars } from '../common/index.mjs';
22

33
import assert from 'assert';
44
import fs from 'fs';
@@ -264,7 +264,7 @@ function nextdir(dirname) {
264264
}
265265

266266
// It throws error if parent directory of symlink in dest points to src.
267-
{
267+
if (!isInsideDirWithUnusualChars) {
268268
const src = nextdir();
269269
mkdirSync(join(src, 'a'), mustNotMutateObjectDeep({ recursive: true }));
270270
const dest = nextdir();
@@ -279,7 +279,7 @@ function nextdir(dirname) {
279279
}
280280

281281
// It throws error if attempt is made to copy directory to file.
282-
{
282+
if (!isInsideDirWithUnusualChars) {
283283
const src = nextdir();
284284
mkdirSync(src, mustNotMutateObjectDeep({ recursive: true }));
285285
const dest = './test/fixtures/copy/kitchen-sink/README.md';
@@ -310,7 +310,7 @@ function nextdir(dirname) {
310310

311311

312312
// It throws error if attempt is made to copy file to directory.
313-
{
313+
if (!isInsideDirWithUnusualChars) {
314314
const src = './test/fixtures/copy/kitchen-sink/README.md';
315315
const dest = nextdir();
316316
mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
@@ -346,7 +346,7 @@ function nextdir(dirname) {
346346

347347
// It throws error if attempt is made to copy src to dest
348348
// when src is parent directory of the parent of dest
349-
{
349+
if (!isInsideDirWithUnusualChars) {
350350
const src = nextdir('a');
351351
const destParent = nextdir('a/b');
352352
const dest = nextdir('a/b/c');
@@ -370,7 +370,7 @@ function nextdir(dirname) {
370370
}
371371

372372
// It throws an error if attempt is made to copy socket.
373-
if (!isWindows) {
373+
if (!isWindows && !isInsideDirWithUnusualChars) {
374374
const src = nextdir();
375375
mkdirSync(src);
376376
const dest = nextdir();
@@ -738,7 +738,7 @@ if (!isWindows) {
738738
}
739739

740740
// It returns an error if attempt is made to copy socket.
741-
if (!isWindows) {
741+
if (!isWindows && !isInsideDirWithUnusualChars) {
742742
const src = nextdir();
743743
mkdirSync(src);
744744
const dest = nextdir();

test/parallel/test-inspector-strip-types.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ if (!process.config.variables.node_use_amaro) common.skip('Requires Amaro');
77
const { NodeInstance } = require('../common/inspector-helper.js');
88
const fixtures = require('../common/fixtures');
99
const assert = require('assert');
10+
const { pathToFileURL } = require('url');
1011

1112
const scriptPath = fixtures.path('typescript/ts/test-typescript.ts');
13+
const scriptURL = pathToFileURL(scriptPath);
1214

1315
async function runTest() {
1416
const child = new NodeInstance(
@@ -30,10 +32,10 @@ async function runTest() {
3032
const scriptParsed = await session.waitForNotification((notification) => {
3133
if (notification.method !== 'Debugger.scriptParsed') return false;
3234

33-
return notification.params.url === scriptPath;
35+
return notification.params.url === scriptPath || notification.params.url === scriptURL.href;
3436
});
3537
// Verify that the script has a sourceURL, hinting that it is a generated source.
36-
assert(scriptParsed.params.hasSourceURL);
38+
assert(scriptParsed.params.hasSourceURL || common.isInsideDirWithUnusualChars);
3739

3840
await session.waitForPauseOnStart();
3941
await session.runToCompletion();

test/parallel/test-npm-install.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const common = require('../common');
33
if (!common.hasCrypto)
44
common.skip('missing crypto');
5+
if (common.isInsideDirWithUnusualChars)
6+
common.skip('npm does not support this install path');
57

68
const path = require('path');
79
const exec = require('child_process').exec;

test/parallel/test-snapshot-child-process-sync.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This tests that process.cwd() is accurate when
44
// restoring state from a snapshot
55

6-
require('../common');
6+
const { isInsideDirWithUnusualChars } = require('../common');
77
const { spawnSyncAndAssert } = require('../common/child_process');
88
const tmpdir = require('../common/tmpdir');
99
const fixtures = require('../common/fixtures');
@@ -14,7 +14,7 @@ const blobPath = tmpdir.resolve('snapshot.blob');
1414
const file = fixtures.path('snapshot', 'child-process-sync.js');
1515
const expected = [
1616
'From child process spawnSync',
17-
'From child process execSync',
17+
...(isInsideDirWithUnusualChars ? [] : ['From child process execSync']),
1818
'From child process execFileSync',
1919
];
2020

@@ -27,6 +27,7 @@ const expected = [
2727
file,
2828
], {
2929
cwd: tmpdir.path,
30+
env: { ...process.env, DIRNAME_CONTAINS_SHELL_UNSAFE_CHARS: isInsideDirWithUnusualChars ? 'TRUE' : '' },
3031
}, {
3132
trim: true,
3233
stdout(output) {
@@ -43,6 +44,7 @@ const expected = [
4344
file,
4445
], {
4546
cwd: tmpdir.path,
47+
env: { ...process.env, DIRNAME_CONTAINS_SHELL_UNSAFE_CHARS: isInsideDirWithUnusualChars ? 'TRUE' : '' },
4648
}, {
4749
trim: true,
4850
stdout(output) {

test/parallel/test-startup-empty-regexp-statics.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
'use strict';
22

33
const common = require('../common');
4+
5+
if (common.isInsideDirWithUnusualChars) {
6+
common.skip('expected failure');
7+
}
8+
49
const assert = require('node:assert');
510
const { spawnSync, spawn } = require('node:child_process');
611

@@ -66,7 +71,7 @@ const allRegExpStatics =
6671
assert.strictEqual(child.signal, null);
6772
}
6873

69-
{
74+
if (!common.isInsideDirWithUnusualChars) {
7075
const child = spawn(process.execPath, [], { stdio: ['pipe', 'pipe', 'inherit'], encoding: 'utf8' });
7176

7277
let stdout = '';
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
// We must load the CJS version here because the ESM wrapper call `hasIPv6`
22
// which compiles a RegEx.
33
// eslint-disable-next-line node-core/require-common-first
4-
import '../common/index.js';
4+
import common from '../common/index.js';
55
import assert from 'node:assert';
66

7-
assert.strictEqual(RegExp.$_, '');
8-
assert.strictEqual(RegExp.$0, undefined);
9-
assert.strictEqual(RegExp.$1, '');
10-
assert.strictEqual(RegExp.$2, '');
11-
assert.strictEqual(RegExp.$3, '');
12-
assert.strictEqual(RegExp.$4, '');
13-
assert.strictEqual(RegExp.$5, '');
14-
assert.strictEqual(RegExp.$6, '');
15-
assert.strictEqual(RegExp.$7, '');
16-
assert.strictEqual(RegExp.$8, '');
17-
assert.strictEqual(RegExp.$9, '');
18-
assert.strictEqual(RegExp.input, '');
19-
assert.strictEqual(RegExp.lastMatch, '');
20-
assert.strictEqual(RegExp.lastParen, '');
21-
assert.strictEqual(RegExp.leftContext, '');
22-
assert.strictEqual(RegExp.rightContext, '');
23-
assert.strictEqual(RegExp['$&'], '');
24-
assert.strictEqual(RegExp['$`'], '');
25-
assert.strictEqual(RegExp['$+'], '');
26-
assert.strictEqual(RegExp["$'"], '');
7+
if (!common.isInsideDirWithUnusualChars) {
8+
assert.strictEqual(RegExp.$_, '');
9+
assert.strictEqual(RegExp.$0, undefined);
10+
assert.strictEqual(RegExp.$1, '');
11+
assert.strictEqual(RegExp.$2, '');
12+
assert.strictEqual(RegExp.$3, '');
13+
assert.strictEqual(RegExp.$4, '');
14+
assert.strictEqual(RegExp.$5, '');
15+
assert.strictEqual(RegExp.$6, '');
16+
assert.strictEqual(RegExp.$7, '');
17+
assert.strictEqual(RegExp.$8, '');
18+
assert.strictEqual(RegExp.$9, '');
19+
assert.strictEqual(RegExp.input, '');
20+
assert.strictEqual(RegExp.lastMatch, '');
21+
assert.strictEqual(RegExp.lastParen, '');
22+
assert.strictEqual(RegExp.leftContext, '');
23+
assert.strictEqual(RegExp.rightContext, '');
24+
assert.strictEqual(RegExp['$&'], '');
25+
assert.strictEqual(RegExp['$`'], '');
26+
assert.strictEqual(RegExp['$+'], '');
27+
assert.strictEqual(RegExp["$'"], '');
28+
}

0 commit comments

Comments
 (0)