aboutsummaryrefslogtreecommitdiff
path: root/test/js/third_party/fsevents/fsevents.test.ts
blob: 1381347e961b01cec3b23fe60297b585573bd283 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { bunEnv, bunExe } from "harness";
import path from "path";
import fs from "fs";
import os from "os";

test("fsevents works (napi_ref_threadsafe_function keeps event loop alive)", async () => {
  const tempFile = fs.mkdtempSync(path.join(os.tmpdir(), "fsevents-test-"));
  const spawned = Bun.spawn({
    cmd: [bunExe(), "run", path.join(import.meta.dir, "fsevents-event-loop.mjs"), tempFile],
    env: bunEnv,
    stdio: ["pipe", "pipe", "pipe"],
  });
  await Bun.sleep(50);
  if (spawned.killed) {
    throw new Error("event loop died, test failed");
  }
  await Bun.write(tempFile + "/hello.txt", "test");
  expect(await spawned.exited).toBe(0);
  expect(await new Response(spawned.stdout).text()).toBe("it works!\n");
});