From e97c082f5ceb6b03a6188bf7e4caa76bf58617fa Mon Sep 17 00:00:00 2001 From: Pietro Marchini Date: Sun, 22 Sep 2024 21:39:06 +0200 Subject: [PATCH] test: apply suggestions --- test/fixtures/test-runner-watch.mjs | 4 ++-- test/parallel/test-runner-watch-mode.mjs | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/test/fixtures/test-runner-watch.mjs b/test/fixtures/test-runner-watch.mjs index 69b727fc55e3e4..72b0a111d46723 100644 --- a/test/fixtures/test-runner-watch.mjs +++ b/test/fixtures/test-runner-watch.mjs @@ -37,6 +37,6 @@ if (values.isolation) { run({ files, watch: true, - ...(cwd ? { cwd } : {}), - ...(isolation ? { isolation } : {}), + cwd, + isolation, }).compose(tap).pipe(process.stdout); diff --git a/test/parallel/test-runner-watch-mode.mjs b/test/parallel/test-runner-watch-mode.mjs index 4230f8eb72b644..0c56e4c20e5b37 100644 --- a/test/parallel/test-runner-watch-mode.mjs +++ b/test/parallel/test-runner-watch-mode.mjs @@ -5,6 +5,7 @@ import { once } from 'node:events'; import assert from 'node:assert'; import { spawn } from 'node:child_process'; import { writeFileSync, renameSync, unlinkSync } from 'node:fs'; +import { setTimeout } from 'node:timers/promises'; import util from 'internal/util'; import tmpdir from '../common/tmpdir.js'; @@ -29,10 +30,6 @@ import('data:text/javascript,'); test('test has ran');`, }; -function wait(ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - function refresh() { tmpdir.refresh(); fixturePaths = Object.keys(fixtureContent) @@ -74,7 +71,7 @@ async function testWatch({ const content = fixtureContent[fileToUpdate]; const path = fixturePaths[fileToUpdate]; writeFileSync(path, content); - await wait(common.platformTimeout(1000)); + await setTimeout(common.platformTimeout(1000)); await ran2.promise; runs.push(currentRun); child.kill(); @@ -97,7 +94,7 @@ async function testWatch({ const fileToRenamePath = tmpdir.resolve(fileToUpdate); const newFileNamePath = tmpdir.resolve(`test-renamed-${fileToUpdate}`); renameSync(fileToRenamePath, newFileNamePath); - await wait(common.platformTimeout(1000)); + await setTimeout(common.platformTimeout(1000)); await ran2.promise; runs.push(currentRun); child.kill(); @@ -119,7 +116,7 @@ async function testWatch({ currentRun = ''; const fileToDeletePath = tmpdir.resolve(fileToUpdate); unlinkSync(fileToDeletePath); - await wait(common.platformTimeout(2000)); + await setTimeout(common.platformTimeout(2000)); ran2.resolve(); runs.push(currentRun); child.kill(); @@ -138,7 +135,7 @@ async function testWatch({ currentRun = ''; const newFilePath = tmpdir.resolve(fileToCreate); writeFileSync(newFilePath, 'module.exports = {};'); - await wait(common.platformTimeout(1000)); + await setTimeout(common.platformTimeout(1000)); await ran2.promise; runs.push(currentRun); child.kill();