import { spawnSync } from "bun"; import { beforeAll, beforeEach, expect, setDefaultTimeout, test } from "bun:test"; import { mkdirSync, writeFileSync } from "fs"; import { bunEnv, bunExe, tmpdirSync } from "harness"; let cwd: string; beforeAll(() => { setDefaultTimeout(1000 * 60 * 5); }); beforeEach(() => { cwd = tmpdirSync(); }); test("bad workspace path", () => { writeFileSync( `${cwd}/package.json`, JSON.stringify( { name: "hey", workspaces: ["i-dont-exist"], }, null, 2, ), ); const { stderr, exitCode } = spawnSync({ cmd: [bunExe(), "install"], cwd, env: bunEnv, stderr: "pipe", stdout: "pipe", }); const text = stderr!.toString(); expect(text).toContain('Workspace not found "i-dont-exist"'); expect(exitCode).toBe(1); }); test("workspace with ./ should not crash", () => { writeFileSync( `${cwd}/package.json`, JSON.stringify( { name: "my-app", version: "1.0.0", workspaces: ["./", "some-workspace"], devDependencies: { "@eslint/js": "^9.28.0", }, }, null, 2, ), ); mkdirSync(`${cwd}/some-workspace`); writeFileSync( `${cwd}/some-workspace/package.json`, JSON.stringify( { name: "some-workspace", version: "1.0.0", }, null, 2, ), ); const { stderr, exitCode } = spawnSync({ cmd: [bunExe(), "install"], cwd, env: bunEnv, stderr: "pipe", stdout: "pipe", }); const text = stderr!.toString(); // Should not crash, should succeed expect(exitCode).toBe(0); expect(text).not.toContain("panic"); expect(text).not.toContain("Internal assertion failure"); }); test("workspace with .\\ should not crash", () => { writeFileSync( `${cwd}/package.json`, JSON.stringify( { name: "my-app", version: "1.0.0", workspaces: [".\\", "some-workspace"], devDependencies: { "@eslint/js": "^9.28.0", }, }, null, 2, ), ); mkdirSync(`${cwd}/some-workspace`); writeFileSync( `${cwd}/some-workspace/package.json`, JSON.stringify( { name: "some-workspace", version: "1.0.0", }, null, 2, ), ); const { stderr, exitCode } = spawnSync({ cmd: [bunExe(), "install"], cwd, env: bunEnv, stderr: "pipe", stdout: "pipe", }); const text = stderr!.toString(); // Should not crash, should succeed expect(exitCode).toBe(0); expect(text).not.toContain("panic"); expect(text).not.toContain("Internal assertion failure"); });