mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
Co-authored-by: nektro <nektro@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
42 lines
918 B
TypeScript
42 lines
918 B
TypeScript
import { it, expect, afterEach } from "bun:test";
|
|
import type { Subprocess } from "bun";
|
|
import { spawn } from "bun";
|
|
import { join } from "node:path";
|
|
import { writeFileSync, rmSync } from "node:fs";
|
|
import { bunExe, bunEnv, tmpdirSync } from "harness";
|
|
|
|
let watchee: Subprocess;
|
|
|
|
it("should watch files", async () => {
|
|
const cwd = tmpdirSync();
|
|
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();
|
|
});
|