aboutsummaryrefslogtreecommitdiff
path: root/test/js/web/fetch/fetch-leak.test.js
blob: fa8b225bd755d509eb7e51e6def3512e644969c8 (plain) (blame)
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
51
52
53
54
55
import { test, expect, describe } from "bun:test";
import { join } from "node:path";
import { bunEnv, bunExe } from "harness";

describe("fetch doesn't leak", () => {
  test("fixture #1", async () => {
    const body = new Blob(["some body in here!".repeat(100)]);
    const server = Bun.serve({
      port: 0,

      fetch(req) {
        return new Response(body);
      },
    });

    const proc = Bun.spawn({
      env: {
        ...bunEnv,
        SERVER: `http://${server.hostname}:${server.port}`,
      },
      stderr: "inherit",
      stdout: "inherit",
      cmd: [bunExe(), join(import.meta.dir, "fetch-leak-test-fixture.js")],
    });

    const exitCode = await proc.exited;
    server.stop(true);
    expect(exitCode).toBe(0);
  });

  test("fixture #2", async () => {
    const body = new Blob(["some body in here!".repeat(100)]);
    const server = Bun.serve({
      port: 0,

      fetch(req) {
        return new Response(body);
      },
    });

    const proc = Bun.spawn({
      env: {
        ...bunEnv,
        SERVER: `http://${server.hostname}:${server.port}`,
      },
      stderr: "inherit",
      stdout: "inherit",
      cmd: [bunExe(), join(import.meta.dir, "fetch-leak-test-fixture-2.js")],
    });

    const exitCode = await proc.exited;
    server.stop(true);
    expect(exitCode).toBe(0);
  });
});