Skip to content

Commit

Permalink
fix hot/hot.test.ts, hot/watch.test.ts, and watch/watch.test.ts (
Browse files Browse the repository at this point in the history
…#13876)

Co-authored-by: dylan-conway <[email protected]>
  • Loading branch information
dylan-conway and dylan-conway authored Sep 11, 2024
1 parent 97baeb8 commit 3e90430
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion test/cli/hot/hot.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -576,6 +577,7 @@ throw new Error('0');`,
stderr: "ignore",
stdin: "ignore",
});
waitForFileToExist(hotRunnerRoot, 20);
await using runner = spawn({
cmd: [
//
Expand Down
2 changes: 1 addition & 1 deletion test/cli/watch/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ for (const dir of ["dir", "©️"]) {
await updateFile(i);
}
rmSync(path);
});
}, 10000);
}

afterEach(() => {
Expand Down
8 changes: 7 additions & 1 deletion test/harness.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3e90430

Please sign in to comment.