Skip to content

Commit d105ef7

Browse files
test: use relative paths within test directory in test-watch-mode.mjs
Signed-off-by: LiviaMedeiros <livia@cirno.name> PR-URL: #67343 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent b0aa887 commit d105ef7

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

‎test/sequential/test-watch-mode.mjs‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as common from '../common/index.mjs';
22
import tmpdir from '../common/tmpdir.js';
33
import assert from 'node:assert';
4-
import os from 'node:os';
54
import path from 'node:path';
65
import { execPath } from 'node:process';
76
import { describe, it } from 'node:test';
@@ -1093,19 +1092,18 @@ process.on('message', (message) => {
10931092
// Honoring --require from NODE_OPTIONS is required for this test.
10941093
skip: !!process.config.variables.node_without_node_options,
10951094
}, async () => {
1096-
// Use /tmp to avoid CI directories with special characters (e.g. ")
1095+
// Use relative path to avoid CI directories with special characters (e.g. ")
10971096
// that would break NODE_OPTIONS parsing.
1098-
const watchDir = path.join(os.tmpdir(), 'test for --watch parsing');
1099-
mkdirSync(watchDir, { recursive: true });
1100-
const reqFile = path.join(watchDir, 'req.cjs');
1097+
const reqFile = tmpdir.resolve('req.cjs');
11011098
writeFileSync(reqFile, 'globalThis.requiredOk = true;');
11021099

11031100
const file = createTmpFile('console.log("required:" + !!globalThis.requiredOk);');
11041101
// Backslashes inside quoted NODE_OPTIONS values are escape characters.
1105-
const nodeOptions = `--watch --require "${reqFile.replaceAll(path.sep, '/')}"`;
1102+
const nodeOptions = '--watch --require ./req.cjs';
11061103
const { done, restart } = runInBackground({
11071104
args: ['--watch', file],
11081105
options: {
1106+
cwd: tmpdir.path,
11091107
env: { ...process.env, NODE_OPTIONS: nodeOptions },
11101108
},
11111109
});
@@ -1170,16 +1168,17 @@ process.on('message', (message) => {
11701168

11711169
it('should strip multiple --watch-path entries from NODE_OPTIONS', async () => {
11721170
const file = createTmpFile('console.log(process.env.NODE_OPTIONS);');
1173-
// Use /tmp to avoid CI directories with special characters (e.g. ")
1171+
// Use relative path to avoid CI directories with special characters (e.g. ")
11741172
// that would break NODE_OPTIONS parsing.
1175-
const dirA = path.join(os.tmpdir(), 'node-watch-path-a');
1176-
const dirB = path.join(os.tmpdir(), 'node-watch-path-b');
1173+
const dirA = tmpdir.resolve('node-watch-path-a');
1174+
const dirB = tmpdir.resolve('node-watch-path-b');
11771175
mkdirSync(dirA, { recursive: true });
11781176
mkdirSync(dirB, { recursive: true });
1179-
const nodeOptions = `--watch --watch-path=${dirA} --watch-path ${dirB} --no-warnings`;
1177+
const nodeOptions = '--watch --watch-path=./node-watch-path-a --watch-path ./node-watch-path-b --no-warnings';
11801178
const { done, restart } = runInBackground({
11811179
args: ['--watch', file],
11821180
options: {
1181+
cwd: tmpdir.path,
11831182
env: { ...process.env, NODE_OPTIONS: nodeOptions },
11841183
},
11851184
});

0 commit comments

Comments
 (0)