Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
richardlau authored and danielleadams committed Dec 30, 2022

Verified

This commit was signed with the committer’s verified signature.
danielleadams Danielle Adams
1 parent 862787a commit 9231477
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/fixtures/watch-mode/ipc.js
Original file line number Diff line number Diff line change
@@ -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) });
3 changes: 1 addition & 2 deletions test/parallel/test-watch-mode-files_watcher.mjs
Original file line number Diff line number Diff line change
@@ -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';
@@ -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));
}

0 comments on commit 9231477

Please sign in to comment.