aboutsummaryrefslogtreecommitdiff
path: root/test/js/third_party/es-module-lexer/es-module-lexer.test.ts
blob: 2202a61a67b621eb92385d4dde6ab0ecb63ba7fd (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
import { test, expect } from "bun:test";
import { spawnSync } from "bun";
import { bunEnv, bunExe } from "../../../harness";
import { join } from "path";

// The purpose of this test is to check that event loop tasks scheduled from
// JavaScriptCore (rather than Bun) keep the process alive.
//
// The problem used to be that Bun would close prematurely when async work was
// scheduled by JavaScriptCore.
//
// At the time of writing, this includes WebAssembly compilation and Atomics
// It excludes FinalizationRegistry since that doesn't need to keep the process alive.
test("es-module-lexer consistently loads", () => {
  for (let i = 0; i < 10; i++) {
    const { stdout, exitCode } = spawnSync({
      cmd: [bunExe(), join(import.meta.dir, "index.ts")],
      env: bunEnv,
    });
    expect(JSON.parse(stdout?.toString())).toEqual({
      imports: [
        {
          n: "b",
          s: 19,
          e: 20,
          ss: 0,
          se: 21,
          d: -1,
          a: -1,
        },
      ],
      exports: [
        {
          s: 36,
          e: 37,
          ls: 36,
          le: 37,
          n: "c",
          ln: "c",
        },
      ],
    });
    expect(exitCode).toBe(42);
  }
});