aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/esbuild-child_process.test.ts
blob: a7eb4f079e5f4bbb4a7ec1ef1e8aca742a00e556 (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
import { transform, transformSync } from "esbuild";
import { describe, it, expect } from "bun:test";

describe("child_process.spawn - esbuild", () => {
  it("should transform successfully", async () => {
    const result = await transform("console.log('hello world')", {
      loader: "js",
      target: "node12",
    });
    expect(result.code).toBe('console.log("hello world");\n');
  });

  it("works for input exceeding the pipe capacity", async () => {
    const hugeString = `console.log(${JSON.stringify("a".repeat(1000000))});`;

    for (let i = 0; i < 2; i++) {
      const result = await transform(hugeString, {
        loader: "js",
        target: "node12",
      });
      expect(result.code).toBe(hugeString + "\n");
    }
  });
});

describe("child_process.spawnSync - esbuild", () => {
  it("should transform successfully", () => {
    const result = transformSync("console.log('hello world')", {
      loader: "js",
      target: "node12",
    });
    expect(result.code).toBe('console.log("hello world");\n');
  });

  // This test is failing with the following error:
  // error: Error
  // path: "/Users/jarred/Code/bun/test/bun.js/node_modules/esbuild-darwin-arm64/bin/esbuild"
  // code: "13"
  // syscall: "spawnSync"
  // errno: -1
  it("works for input exceeding the pipe capacity", () => {
    const hugeString = `console.log(${JSON.stringify("a".repeat(100000))});`;
    const result = transformSync(hugeString, {
      loader: "js",
      target: "node12",
    });
    expect(result.code).toBe(hugeString + "\n");
  });
});