From 6d74b9048da56345ca53cc50950106d728cb70ed Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Thu, 27 Oct 2022 10:10:20 -0400 Subject: [PATCH] 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. --- 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)); }