Skip to content

Commit 02ebde3

Browse files
richardlauRafaelGSS
authored andcommitted
test: use common/tmpdir in watch-mode ipc test
Using `path.join(os.tmpdir(), 'file')` on a multi-user system can lead to file collisions where the file already exists but is owned by a different user and cannot be removed or overwritten. Other tests in `parallel/test-watch-mode-files_watcher` use `common/tmpdir` instead so switch to that for consistency. PR-URL: #45211 Refs: #44366 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]>
1 parent 49be13c commit 02ebde3

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

test/fixtures/watch-mode/ipc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const path = require('node:path');
22
const url = require('node:url');
3-
const os = require('node:os');
43
const fs = require('node:fs');
4+
const tmpdir = require('../../common/tmpdir');
55

6-
const tmpfile = path.join(os.tmpdir(), 'file');
6+
const tmpfile = path.join(tmpdir.path, 'file');
77
fs.writeFileSync(tmpfile, '');
88

99
process.send({ 'watch:require': path.resolve(__filename) });

test/parallel/test-watch-mode-files_watcher.mjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import tmpdir from '../common/tmpdir.js';
55
import path from 'node:path';
66
import assert from 'node:assert';
77
import process from 'node:process';
8-
import os from 'node:os';
98
import { describe, it, beforeEach, afterEach } from 'node:test';
109
import { writeFileSync, mkdirSync } from 'node:fs';
1110
import { setTimeout } from 'node:timers/promises';
@@ -153,7 +152,7 @@ describe('watch mode file watcher', () => {
153152
const child = spawn(process.execPath, [file], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'], encoding: 'utf8' });
154153
watcher.watchChildProcessModules(child);
155154
await once(child, 'exit');
156-
let expected = [file, path.join(os.tmpdir(), 'file')];
155+
let expected = [file, path.join(tmpdir.path, 'file')];
157156
if (supportsRecursiveWatching) {
158157
expected = expected.map((file) => path.dirname(file));
159158
}

0 commit comments

Comments
 (0)