mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 04:18:58 +00:00
* draft impl of windows watcher * synchronous watcher * working standalone watcher * in progress changes to watcher * make watcher non-global * prepare watcher for windows impl * add windows watcher scaffold and clean up imports * fix inotify * make watch code more generic over platforms * fix visibility * watcher starts without error * printing changes works * basic windows watching works * handle process exit from watcher * cleanup in process cloning * clean up logging and panic handling * fix hot reload test on windows * misc cleanup around watcher * make watch test actually useful * [autofix.ci] apply automated fixes * remove old files * clean up watchers * update .gitignore * rework windows watcher into single watcher instance watching top level project dir * use non-strict utf16 conversion * change to contains * fix mac and linux compile * add baseline in crash report (#8606) * allow linking bins that do not exist. (#8605) * fix linux compile * fix linux compile (again) * remove outdated todo --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dave caruso <me@paperdave.net>
43 lines
981 B
TypeScript
43 lines
981 B
TypeScript
import { it, expect, afterEach } from "bun:test";
|
|
import type { Subprocess } from "bun";
|
|
import { spawn } from "bun";
|
|
import { join } from "node:path";
|
|
import { tmpdir } from "node:os";
|
|
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
|
|
import { bunExe, bunEnv } from "harness";
|
|
|
|
let watchee: Subprocess;
|
|
|
|
it("should watch files", async () => {
|
|
const cwd = mkdtempSync(join(tmpdir(), "bun-test-"));
|
|
const path = join(cwd, "watchee.js");
|
|
|
|
const updateFile = (i: number) => {
|
|
writeFileSync(path, `console.log(${i});`);
|
|
};
|
|
|
|
let i = 0;
|
|
updateFile(i);
|
|
watchee = spawn({
|
|
cwd,
|
|
cmd: [bunExe(), "--watch", "watchee.js"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "inherit",
|
|
stdin: "ignore",
|
|
});
|
|
|
|
for await (const line of watchee.stdout) {
|
|
if (i == 10) break;
|
|
var str = new TextDecoder().decode(line);
|
|
expect(str).toContain(`${i}`);
|
|
i++;
|
|
updateFile(i);
|
|
}
|
|
rmSync(path);
|
|
});
|
|
|
|
afterEach(() => {
|
|
watchee?.kill();
|
|
});
|