From 02ebde39d36d1a012623fa34d746d7bb963c6d61 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 28 Oct 2022 12:29:41 +0100 Subject: [PATCH] test: use common/tmpdir in watch-mode ipc test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/45211 Refs: https://github.com/nodejs/node/pull/44366 Reviewed-By: Moshe Atlow Reviewed-By: Colin Ihrig Reviewed-By: Juan José Arboleda --- test/fixtures/watch-mode/ipc.js | 4 ++-- test/parallel/test-watch-mode-files_watcher.mjs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/fixtures/watch-mode/ipc.js b/test/fixtures/watch-mode/ipc.js index 31e1bd0e5c589f..021df9973511d0 100644 --- a/test/fixtures/watch-mode/ipc.js +++ b/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) }); diff --git a/test/parallel/test-watch-mode-files_watcher.mjs b/test/parallel/test-watch-mode-files_watcher.mjs index 1c3088800bd5d9..4c507d61e00c7f 100644 --- a/test/parallel/test-watch-mode-files_watcher.mjs +++ b/test/parallel/test-watch-mode-files_watcher.mjs @@ -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)); }