diff options
| author | 2023-07-30 07:54:17 -0700 | |
|---|---|---|
| committer | 2023-07-30 07:54:17 -0700 | |
| commit | 54a2d89bd277ef6ddbe95b322e6b8e1a308e059e (patch) | |
| tree | ee784bf7bcd497480795fbb6e8e0dcad7e42095a /test | |
| parent | 0ea59b4c93e2fa285955e9129b3f219b07e30779 (diff) | |
| download | bun-54a2d89bd277ef6ddbe95b322e6b8e1a308e059e.tar.gz bun-54a2d89bd277ef6ddbe95b322e6b8e1a308e059e.tar.zst bun-54a2d89bd277ef6ddbe95b322e6b8e1a308e059e.zip | |
Support `bun .` to run the entry point (#3891)
* Support `bun .`
* Fix tests
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/cli/install/bun-run.test.ts | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/test/cli/install/bun-run.test.ts b/test/cli/install/bun-run.test.ts index 95f33ebb8..4180c9716 100644 --- a/test/cli/install/bun-run.test.ts +++ b/test/cli/install/bun-run.test.ts @@ -1,6 +1,6 @@ -import { file, spawn } from "bun"; -import { afterEach, beforeEach, expect, it } from "bun:test"; -import { bunExe, bunEnv as env } from "harness"; +import { file, spawn, spawnSync } from "bun"; +import { afterEach, beforeEach, expect, it, describe } from "bun:test"; +import { bunEnv, bunExe, bunEnv as env } from "harness"; import { mkdtemp, realpath, rm, writeFile } from "fs/promises"; import { tmpdir } from "os"; import { join } from "path"; @@ -9,12 +9,76 @@ import { readdirSorted } from "./dummy.registry"; let run_dir: string; beforeEach(async () => { - run_dir = await realpath(await mkdtemp(join(tmpdir(), "bun-run.test"))); + run_dir = await realpath( + await mkdtemp(join(tmpdir(), "bun-run.test." + Math.trunc(Math.random() * 9999999).toString(32))), + ); }); afterEach(async () => { await rm(run_dir, { force: true, recursive: true }); }); +for (let withRun of [false, true]) { + describe(withRun ? "bun run" : "bun", () => { + describe("should work with .", () => { + it("respecting 'main' field", async () => { + await writeFile(join(run_dir, "test.js"), "console.log('Hello, world!');"); + await writeFile( + join(run_dir, "package.json"), + JSON.stringify({ + name: "test", + version: "0.0.0", + main: "test.js", + }), + ); + const { stdout, stderr, exitCode } = spawnSync({ + cmd: [bunExe(), withRun ? "run" : "", "."].filter(Boolean), + cwd: run_dir, + env: bunEnv, + }); + + expect(stderr.toString()).toBe(""); + expect(stdout.toString()).toBe("Hello, world!\n"); + expect(exitCode).toBe(0); + }); + + it("falling back to index", async () => { + await writeFile(join(run_dir, "index.ts"), "console.log('Hello, world!');"); + await writeFile( + join(run_dir, "package.json"), + JSON.stringify({ + name: "test", + version: "0.0.0", + }), + ); + + const { stdout, stderr, exitCode } = spawnSync({ + cmd: [bunExe(), withRun ? "run" : "", "."].filter(Boolean), + cwd: run_dir, + env: bunEnv, + }); + + expect(stderr.toString()).toBe(""); + expect(stdout.toString()).toBe("Hello, world!\n"); + expect(exitCode).toBe(0); + }); + + it("falling back to index with no package.json", async () => { + await writeFile(join(run_dir, "index.ts"), "console.log('Hello, world!');"); + + const { stdout, stderr, exitCode } = spawnSync({ + cmd: [bunExe(), withRun ? "run" : "", "."].filter(Boolean), + cwd: run_dir, + env: bunEnv, + }); + + expect(stderr.toString()).toBe(""); + expect(stdout.toString()).toBe("Hello, world!\n"); + expect(exitCode).toBe(0); + }); + }); + }); +} + it("should download dependency to run local file", async () => { await writeFile( join(run_dir, "test.js"), |
