|
1 | 1 | import * as common from '../common/index.mjs'; |
2 | 2 | import tmpdir from '../common/tmpdir.js'; |
3 | 3 | import assert from 'node:assert'; |
4 | | -import os from 'node:os'; |
5 | 4 | import path from 'node:path'; |
6 | 5 | import { execPath } from 'node:process'; |
7 | 6 | import { describe, it } from 'node:test'; |
@@ -1093,19 +1092,18 @@ process.on('message', (message) => { |
1093 | 1092 | // Honoring --require from NODE_OPTIONS is required for this test. |
1094 | 1093 | skip: !!process.config.variables.node_without_node_options, |
1095 | 1094 | }, 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. ") |
1097 | 1096 | // 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'); |
1101 | 1098 | writeFileSync(reqFile, 'globalThis.requiredOk = true;'); |
1102 | 1099 |
|
1103 | 1100 | const file = createTmpFile('console.log("required:" + !!globalThis.requiredOk);'); |
1104 | 1101 | // 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'; |
1106 | 1103 | const { done, restart } = runInBackground({ |
1107 | 1104 | args: ['--watch', file], |
1108 | 1105 | options: { |
| 1106 | + cwd: tmpdir.path, |
1109 | 1107 | env: { ...process.env, NODE_OPTIONS: nodeOptions }, |
1110 | 1108 | }, |
1111 | 1109 | }); |
@@ -1170,16 +1168,17 @@ process.on('message', (message) => { |
1170 | 1168 |
|
1171 | 1169 | it('should strip multiple --watch-path entries from NODE_OPTIONS', async () => { |
1172 | 1170 | 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. ") |
1174 | 1172 | // 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'); |
1177 | 1175 | mkdirSync(dirA, { recursive: true }); |
1178 | 1176 | 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'; |
1180 | 1178 | const { done, restart } = runInBackground({ |
1181 | 1179 | args: ['--watch', file], |
1182 | 1180 | options: { |
| 1181 | + cwd: tmpdir.path, |
1183 | 1182 | env: { ...process.env, NODE_OPTIONS: nodeOptions }, |
1184 | 1183 | }, |
1185 | 1184 | }); |
|
0 commit comments