-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
watch.test.ts
44 lines (38 loc) · 1.09 KB
/
watch.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
await Bun.sleep(1000);
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();
});