diff options
author | 2023-01-24 04:08:24 -0800 | |
---|---|---|
committer | 2023-01-24 04:08:24 -0800 | |
commit | be79f6e893a3a94e13c1fa85d71f900546123d17 (patch) | |
tree | 295d54c10fc8b029f7b1c460ae90cda5c67355a0 /test | |
parent | bb5119f7eb7bd6ebd20374d47aebebe22a6b2687 (diff) | |
download | bun-be79f6e893a3a94e13c1fa85d71f900546123d17.tar.gz bun-be79f6e893a3a94e13c1fa85d71f900546123d17.tar.zst bun-be79f6e893a3a94e13c1fa85d71f900546123d17.zip |
Add failing test
Diffstat (limited to 'test')
-rw-r--r-- | test/bun.js/hot.test.ts | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/test/bun.js/hot.test.ts b/test/bun.js/hot.test.ts index a862d13ce..bd75d59ee 100644 --- a/test/bun.js/hot.test.ts +++ b/test/bun.js/hot.test.ts @@ -20,25 +20,63 @@ it("should hot reload when file is overwritten", async () => { writeFileSync(root, readFileSync(root, "utf-8")); } - await (async function () { - for await (const line of runner.stdout!) { - var str = new TextDecoder().decode(line); + for await (const line of runner.stdout!) { + var str = new TextDecoder().decode(line); - if (str.includes("[#!root]")) { - reloadCounter++; + if (str.includes("[#!root]")) { + reloadCounter++; - if (reloadCounter === 3) { - runner.unref(); - runner.kill(); - return; - } + if (reloadCounter === 3) { + runner.unref(); + runner.kill(); + break; + } + + expect(str).toContain(`[#!root] Reloaded: ${reloadCounter}`); + + await onReload(); + } + } + + expect(reloadCounter).toBe(3); +}); + +// This test fails +it.skip("should hot reload when a file is deleted and rewritten", 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", + }); - expect(str).toContain(`[#!root] Reloaded: ${reloadCounter}`); + var reloadCounter = 0; - await onReload(); + async function onReload() { + const contents = readFileSync(root, "utf-8"); + unlinkSync(root); + writeFileSync(root, contents); + } + + for await (const line of runner.stdout!) { + var str = new TextDecoder().decode(line); + + if (str.includes("[#!root]")) { + reloadCounter++; + + if (reloadCounter === 3) { + runner.unref(); + runner.kill(); + break; } + + expect(str).toContain(`[#!root] Reloaded: ${reloadCounter}`); + + await onReload(); } - })(); + } expect(reloadCounter).toBe(3); }); |