From 3e904303acbfdb01c698b74a123343185ac306ff Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Wed, 11 Sep 2024 01:24:46 -0700 Subject: [PATCH] fix `hot/hot.test.ts`, `hot/watch.test.ts`, and `watch/watch.test.ts` (#13876) Co-authored-by: dylan-conway --- test/cli/hot/hot.test.ts | 4 +++- test/cli/watch/watch.test.ts | 2 +- test/harness.ts | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/cli/hot/hot.test.ts b/test/cli/hot/hot.test.ts index 81d4e046d8..b819cdff2f 100644 --- a/test/cli/hot/hot.test.ts +++ b/test/cli/hot/hot.test.ts @@ -1,7 +1,7 @@ import { spawn } from "bun"; import { beforeEach, expect, it } from "bun:test"; import { copyFileSync, cpSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "fs"; -import { bunEnv, bunExe, isDebug, tmpdirSync } from "harness"; +import { bunEnv, bunExe, isDebug, tmpdirSync, waitForFileToExist } from "harness"; import { join } from "path"; const timeout = isDebug ? Infinity : 10_000; @@ -487,6 +487,7 @@ throw new Error('0');`, stderr: "inherit", stdin: "ignore", }); + waitForFileToExist(hotRunnerRoot, 20); await using runner = spawn({ cmd: [bunExe(), "--hot", "run", hotRunnerRoot], env: bunEnv, @@ -576,6 +577,7 @@ throw new Error('0');`, stderr: "ignore", stdin: "ignore", }); + waitForFileToExist(hotRunnerRoot, 20); await using runner = spawn({ cmd: [ // diff --git a/test/cli/watch/watch.test.ts b/test/cli/watch/watch.test.ts index 01ef6d03dd..49b7896b21 100644 --- a/test/cli/watch/watch.test.ts +++ b/test/cli/watch/watch.test.ts @@ -35,7 +35,7 @@ for (const dir of ["dir", "©️"]) { await updateFile(i); } rmSync(path); - }); + }, 10000); } afterEach(() => { diff --git a/test/harness.ts b/test/harness.ts index cf508d431f..8b5877a51a 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -1,4 +1,4 @@ -import { gc as bunGC, spawnSync, unsafe, which } from "bun"; +import { gc as bunGC, sleepSync, spawnSync, unsafe, which } from "bun"; import { heapStats } from "bun:jsc"; import { afterAll, beforeAll, describe, expect, test } from "bun:test"; import { readFile, readlink, writeFile } from "fs/promises"; @@ -1284,3 +1284,9 @@ Object.defineProperty(globalThis, "gc", { enumerable: false, configurable: true, }); + +export function waitForFileToExist(path: string, interval: number) { + while (!fs.existsSync(path)) { + sleepSync(interval); + } +}