aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
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"]);
+});