-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.test.ts
70 lines (60 loc) · 1.88 KB
/
add.test.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { createDirectory, isDirectory, writePackage } from "@mokr/core";
import assert from "node:assert";
import { beforeEach, describe, it } from "node:test";
import { temporaryDirectory } from "tempy";
import cli from "../src/cli.js";
describe("add", () => {
let tempDir: string;
beforeEach(() => {
tempDir = temporaryDirectory();
});
it("should only run within monorepos", async () => {
await assert.rejects(cli.run(`add --cwd ${tempDir} foo`), {
name: "Error",
message: "Execute this command from within a monorepo",
});
});
it("needs a workspace configuration", async () => {
await createDirectory({ directory: `${tempDir}/.git` });
await writePackage({
directory: tempDir,
data: {
moker: { scoped: true },
},
});
await assert.rejects(cli.run(`add --cwd ${tempDir} foo`), {
name: "Error",
message: "No workspace configuration found in package.json",
});
});
it("should add a workspace", async () => {
await createDirectory({ directory: `${tempDir}/.git` });
await writePackage({
directory: tempDir,
data: {
name: "foo",
workspaces: ["packages/*"],
moker: { scoped: true },
},
});
await cli.run(`add --cwd ${tempDir} foo`);
});
it("should not confuse templates and workspace names", async () => {
/**
* @todo: remove when https://github.com/nodejs/node/issues/47614 resolves
*/
if (!process.versions.node.startsWith("20.")) {
await createDirectory({ directory: `${tempDir}/.git` });
await writePackage({
directory: tempDir,
data: {
name: "foo",
workspaces: ["packages/*"],
moker: { scoped: true },
},
});
await cli.run(`add --cwd ${tempDir} --template bar foo`);
assert(await isDirectory({ directory: `${tempDir}/packages/foo` }));
}
});
});