aboutsummaryrefslogtreecommitdiff
path: root/test/cli/install/bad-workspace.test.ts
blob: 0c72c2fd23a28b0a0f741f67d43f661fe2b2675f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
});