Files
bun.sh/test/cli/hot/watch.test.ts
Jarred Sumner c71325b52e Fix regression with console.log in --watch on linux (#9601)
* Fix regression with console.log in --watch on linux

* Unset CLOEXEC

* more

* Enable inheritance on windows

* Don't forget to close the handles...

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2024-03-24 18:38:41 -07:00

51 lines
1.7 KiB
TypeScript

import { spawn } from "bun";
import { describe, expect, test } from "bun:test";
import { writeFile } from "fs/promises";
import { bunEnv, bunExe, forEachLine, tempDirWithFiles } from "harness";
import { join } from "path";
describe("--watch works", async () => {
for (let watchedFile of ["tmp.js", "entry.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" }),
});
const tmpfile = join(tmpdir_, "tmp.js");
await writeFile(tmpfile, "console.log('hello #1')");
const process = spawn({
cmd: [bunExe(), "--watch", join(tmpdir_, watchedFile)],
cwd: tmpdir_,
env: bunEnv,
stdio: ["ignore", "pipe", "inherit"],
});
const { stdout } = process;
let 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();
await process.exited;
});
}
});