diff options
author | 2023-01-26 23:21:10 -0800 | |
---|---|---|
committer | 2023-01-26 23:21:10 -0800 | |
commit | ed5bcfc76bbcd382441b9519253d6f5d7a18556b (patch) | |
tree | d720c1eccca471b2558d47ad351876f370f2a756 | |
parent | 421588d63119fb15cd4db06838bb7058d72cc727 (diff) | |
download | bun-ed5bcfc76bbcd382441b9519253d6f5d7a18556b.tar.gz bun-ed5bcfc76bbcd382441b9519253d6f5d7a18556b.tar.zst bun-ed5bcfc76bbcd382441b9519253d6f5d7a18556b.zip |
Another test
-rw-r--r-- | test/bun.js/hot.test.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/bun.js/hot.test.ts b/test/bun.js/hot.test.ts index d95b6c7a9..c7c8d0524 100644 --- a/test/bun.js/hot.test.ts +++ b/test/bun.js/hot.test.ts @@ -49,6 +49,57 @@ it("should hot reload when file is overwritten", async () => { expect(reloadCounter).toBe(3); }); +it("should not hot reload when a random file is written", async () => { + const root = import.meta.dir + "/hot-runner.js"; + const runner = spawn({ + cmd: [bunExe(), "--hot", "run", root], + env: bunEnv, + stdout: "pipe", + stderr: "inherit", + stdin: "ignore", + }); + + var reloadCounter = 0; + + async function onReload() { + writeFileSync(root + ".another.yet.js", readFileSync(root, "utf-8")); + unlinkSync(root + ".another.yet.js"); + } + var waiter = new Promise<void>((resolve, reject) => { + setTimeout(async () => { + resolve(); + }, 10); + }); + var finished = false; + await Promise.race([ + waiter, + (async () => { + if (finished) { + return; + } + for await (const line of runner.stdout!) { + if (finished) { + return; + } + + var str = new TextDecoder().decode(line); + for (let line of str.split("\n")) { + if (!line.includes("[#!root]")) continue; + await onReload(); + + reloadCounter++; + expect(str).toContain(`[#!root] Reloaded: ${reloadCounter}`); + } + } + })(), + ]); + finished = true; + runner.kill(0); + runner.unref(); + + expect(reloadCounter).toBe(0); +}); + it("should hot reload when a file is deleted and rewritten", async () => { const root = import.meta.dir + "/hot-runner.js"; const runner = spawn({ |