aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/socket/socket.test.ts
blob: aff001c75c9a9cc4193d3e856c03c449fd05e0c4 (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
import { expect, it } from "bun:test";
import { bunExe } from "../bunExe";
import { spawn } from "bun";

it("should keep process alive only when active", async () => {
  const { exited, stdout, stderr } = spawn({
    cmd: [ bunExe(), "echo.js" ],
    cwd: import.meta.dir,
    stdout: "pipe",
    stdin: null,
    stderr: "pipe",
    env: {
      BUN_DEBUG_QUIET_LOGS: 1,
    },
  });
  expect(await exited).toBe(0);
  expect(await new Response(stderr).text()).toBe("");
  var lines = (await new Response(stdout).text()).split(/\r?\n/);
  expect(lines.filter(function(line) {
    return line.startsWith("[Server]");
  })).toEqual([
    "[Server] OPENED",
    "[Server] GOT request",
    "[Server] CLOSED",
  ]);
  expect(lines.filter(function(line) {
    return line.startsWith("[Client]");
  })).toEqual([
    "[Client] OPENED",
    "[Client] GOT response",
    "[Client] ENDED",
    "[Client] CLOSED",
  ]);
});