Skip to content

Commit

Permalink
test: use common/tmpdir in watch-mode ipc test
Browse files Browse the repository at this point in the history
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 <moshe@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
  • Loading branch information
richardlau authored and RafaelGSS committed Nov 10, 2022
1 parent 49be13c commit 02ebde3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/fixtures/watch-mode/ipc.js
@@ -1,9 +1,9 @@
const path = require('node:path');
const url = require('node:url');
const os = require('node:os');
const fs = require('node:fs');
const tmpdir = require('../../common/tmpdir');

const tmpfile = path.join(os.tmpdir(), 'file');
const tmpfile = path.join(tmpdir.path, 'file');
fs.writeFileSync(tmpfile, '');

process.send({ 'watch:require': path.resolve(__filename) });
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-watch-mode-files_watcher.mjs
Expand Up @@ -5,7 +5,6 @@ import tmpdir from '../common/tmpdir.js';
import path from 'node:path';
import assert from 'node:assert';
import process from 'node:process';
import os from 'node:os';
import { describe, it, beforeEach, afterEach } from 'node:test';
import { writeFileSync, mkdirSync } from 'node:fs';
import { setTimeout } from 'node:timers/promises';
Expand Down Expand Up @@ -153,7 +152,7 @@ describe('watch mode file watcher', () => {
const child = spawn(process.execPath, [file], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'], encoding: 'utf8' });
watcher.watchChildProcessModules(child);
await once(child, 'exit');
let expected = [file, path.join(os.tmpdir(), 'file')];
let expected = [file, path.join(tmpdir.path, 'file')];
if (supportsRecursiveWatching) {
expected = expected.map((file) => path.dirname(file));
}
Expand Down

0 comments on commit 02ebde3

Please sign in to comment.