mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import type { Subprocess } from "bun";
|
|
import { spawn } from "bun";
|
|
import { afterEach, expect, it } from "bun:test";
|
|
import { bunEnv, bunExe, tmpdirSync } from "harness";
|
|
import { rmSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
let watchee: Subprocess;
|
|
|
|
for (const dir of ["dir", "©️"]) {
|
|
it(`should watch files ${dir === "dir" ? "" : "(non-ascii path)"}`, async () => {
|
|
const cwd = join(tmpdirSync(), dir);
|
|
const path = join(cwd, "watchee.js");
|
|
|
|
const updateFile = async (i: number) => {
|
|
await Bun.write(path, `console.log(${i}, __dirname);`);
|
|
};
|
|
|
|
let i = 0;
|
|
await 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} ${cwd}`);
|
|
i++;
|
|
await updateFile(i);
|
|
}
|
|
rmSync(path);
|
|
}, 10000);
|
|
}
|
|
|
|
afterEach(() => {
|
|
watchee?.kill();
|
|
});
|