diff options
author | 2022-09-07 19:56:23 -0700 | |
---|---|---|
committer | 2022-09-07 19:56:23 -0700 | |
commit | c4b9c1267793e966db5f4ee4caf0c3c745cfe5cb (patch) | |
tree | 075166bc71ac33f5be0ecd29b36bebe6f3ca281a | |
parent | d7759b88eee013dfb6fe7d7fbb9864a1c4b06269 (diff) | |
download | bun-c4b9c1267793e966db5f4ee4caf0c3c745cfe5cb.tar.gz bun-c4b9c1267793e966db5f4ee4caf0c3c745cfe5cb.tar.zst bun-c4b9c1267793e966db5f4ee4caf0c3c745cfe5cb.zip |
Fix flaky tests
-rw-r--r-- | test/bun.js/serve.test.ts | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts index 8961372c1..99b667a2d 100644 --- a/test/bun.js/serve.test.ts +++ b/test/bun.js/serve.test.ts @@ -1,8 +1,10 @@ -import { file, serve } from "bun"; -import { describe, expect, it } from "bun:test"; +import { file, gc, serve } from "bun"; +import { afterEach, describe, expect, it } from "bun:test"; import { readFileSync } from "fs"; import { resolve } from "path"; +afterEach(() => Bun.gc(true)); + var port = 40001; class TestPass extends Error { @@ -38,8 +40,11 @@ describe("streaming", () => { }); const response = await fetch(`http://localhost:${server.port}`); - if (response.status > 0) expect(response.status).toBe(500); - expect(await response.text()).toBe("fail"); + if (response.status > 0) { + expect(response.status).toBe(500); + expect(await response.text()).toBe("fail"); + } + expect(pass).toBe(true); } catch (e) { throw e; @@ -74,8 +79,10 @@ describe("streaming", () => { const response = await fetch(`http://localhost:${server.port}`); // connection terminated - if (response.status > 0) expect(response.status).toBe(200); - expect(await response.text()).toBe("such fail"); + if (response.status > 0) { + expect(response.status).toBe(200); + expect(await response.text()).toBe("such fail"); + } expect(pass).toBe(true); } catch (e) { throw e; @@ -151,6 +158,7 @@ describe("streaming", () => { }); const response = await fetch(`http://localhost:${server.port}`); + console.log("here"); expect(response.status).toBe(500); } catch (e) { if (!e || !(e instanceof TestPass)) { @@ -159,6 +167,7 @@ describe("streaming", () => { } finally { server?.stop(); } + gc(true); }); it("text from JS throws on start has error handler", async () => { @@ -465,7 +474,6 @@ it(`should work for text ${count} times serial`, async () => { server.stop(); }); - it(`should work for ArrayBuffer ${count} times serial`, async () => { const textToExpect = "hello"; var ran = 0; |