-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
watch.test.ts
50 lines (43 loc) · 1.67 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
45
46
47
48
49
50
import { spawn } from "bun";
import { describe, expect, test } from "bun:test";
import { bunEnv, bunExe, forEachLine, tempDirWithFiles } from "harness";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
describe("--watch works", async () => {
for (const watchedFile of ["entry.js", "tmp.js"]) {
test(`with ${watchedFile}`, async () => {
const tmpdir_ = tempDirWithFiles("watch-fixture", {
"tmp.js": "console.log('hello #1')",
"entry.js": "import './tmp.js'",
"package.json": JSON.stringify({ name: "foo", version: "0.0.1" }),
});
await Bun.sleep(1000);
const tmpfile = join(tmpdir_, "tmp.js");
const process = spawn({
cmd: [bunExe(), "--watch", join(tmpdir_, watchedFile)],
cwd: tmpdir_,
env: bunEnv,
stdio: ["ignore", "pipe", "inherit"],
});
const { stdout } = process;
const iter = forEachLine(stdout);
let { value: line, done } = await iter.next();
expect(done).toBe(false);
expect(line).toBe("hello #1");
await writeFile(tmpfile, "console.log('hello #2')");
({ value: line } = await iter.next());
expect(line).toBe("hello #2");
await writeFile(tmpfile, "console.log('hello #3')");
({ value: line } = await iter.next());
expect(line).toBe("hello #3");
await writeFile(tmpfile, "console.log('hello #4')");
({ value: line } = await iter.next());
expect(line).toBe("hello #4");
await writeFile(tmpfile, "console.log('hello #5')");
({ value: line } = await iter.next());
expect(line).toBe("hello #5");
process.kill("SIGKILL");
await process.exited;
});
}
});