aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2023-02-12 06:40:18 +0200
committerGravatar GitHub <noreply@github.com> 2023-02-11 20:40:18 -0800
commit30e82c5df42fab71a238cd9b7d268cbb6510bd7a (patch)
tree8f3c9212696545af28c6eba4a43a35599522cadf /test/bun.js
parent9eba1e0e3fbd9ba80f7cac4a74c860e35335d86e (diff)
downloadbun-30e82c5df42fab71a238cd9b7d268cbb6510bd7a.tar.gz
bun-30e82c5df42fab71a238cd9b7d268cbb6510bd7a.tar.zst
bun-30e82c5df42fab71a238cd9b7d268cbb6510bd7a.zip
fix segfault during non-install script execution (#2045)
Diffstat (limited to 'test/bun.js')
-rw-r--r--test/bun.js/install/bunx.test.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/test/bun.js/install/bunx.test.ts b/test/bun.js/install/bunx.test.ts
index b754ca0c6..08ec3fc50 100644
--- a/test/bun.js/install/bunx.test.ts
+++ b/test/bun.js/install/bunx.test.ts
@@ -3,9 +3,10 @@ import { afterEach, beforeEach, expect, it } from "bun:test";
import { bunExe } from "bunExe";
import { bunEnv as env } from "bunEnv";
import { realpathSync } from "fs";
-import { mkdtemp, rm } from "fs/promises";
+import { mkdtemp, rm, writeFile } from "fs/promises";
import { tmpdir } from "os";
import { join } from "path";
+import { readdirSorted } from "./dummy.registry";
let x_dir;
@@ -51,3 +52,33 @@ it("should install and run specified version", async () => {
expect(out.split(/\r?\n/)).toEqual(["uglify-js 3.14.1", ""]);
expect(await exited).toBe(0);
});
+
+it("should download dependencies to run local file", async () => {
+ await writeFile(
+ join(x_dir, "test.js"),
+ `
+import { minify } from "uglify-js";
+
+console.log(minify("print(6 * 7)").code);
+`,
+ );
+ const { stdout, stderr, exited } = spawn({
+ cmd: [bunExe(), "test.js"],
+ cwd: x_dir,
+ stdout: null,
+ stdin: "pipe",
+ stderr: "pipe",
+ env: {
+ ...env,
+ BUN_INSTALL_CACHE_DIR: join(x_dir, ".cache"),
+ },
+ });
+ expect(stderr).toBeDefined();
+ const err = await new Response(stderr).text();
+ expect(err).toBe("");
+ expect(stdout).toBeDefined();
+ const out = await new Response(stdout).text();
+ expect(out.split(/\r?\n/)).toEqual(["print(42);", ""]);
+ expect(await exited).toBe(0);
+ expect(await readdirSorted(x_dir)).toEqual([".cache", "test.js"]);
+});