Files
bun.sh/test/cli/install/bad-workspace.test.ts
Alex Lam S.L 319efe9c7b [install] fix tests (#2488)
- avoid creating spurious directories next to test scripts
2023-03-25 21:51:03 -07:00

45 lines
1.1 KiB
TypeScript

import { spawnSync } from "bun";
import { afterEach, beforeEach, expect, test } from "bun:test";
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "fs";
import { bunExe, bunEnv } from "harness";
import { join } from "path";
import { tmpdir } from "os";
let cwd: string;
beforeEach(() => {
cwd = mkdtempSync(join(realpathSync(tmpdir()), "bad-workspace.test"));
});
afterEach(() => {
rmSync(cwd, { recursive: true, force: true });
});
test("bad workspace path", () => {
writeFileSync(
`${cwd}/package.json`,
JSON.stringify(
{
name: "hey",
workspaces: ["i-dont-exist", "**/i-have-a-2-stars-and-i-dont-exist", "*/i-have-a-star-and-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(text).toContain("multi level globs");
expect(text).toContain("glob star * in the middle of a path");
expect(exitCode).toBe(1);
});