Skip to content

Commit bb09b8a

Browse files
committed
test: add monorepo e2e tests
1 parent e97ac75 commit bb09b8a

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

e2e/monorepo.test.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { expect, it } from "@jest/globals";
2+
import sandbox from "./utils/sandbox.js";
3+
import json from "./utils/json.js";
4+
import { CONVER } from "./utils/binary.js";
5+
6+
it("bumps only affected packages", async () => {
7+
await sandbox(async (sandbox) => {
8+
// package.json
9+
await sandbox.writeFiles({
10+
"package.json": json({
11+
name: "my-workspace",
12+
version: "0.0.0",
13+
workspaces: ["package-a", "package-b"],
14+
}),
15+
"package-a/package.json": json({
16+
name: "package-a",
17+
version: "1.2.3",
18+
}),
19+
"package-b/package.json": json({
20+
name: "package-b",
21+
version: "1.2.3",
22+
}),
23+
});
24+
25+
// init sandbox
26+
await sandbox.$`git init`;
27+
await sandbox.$`${CONVER} init --yes`;
28+
await sandbox.$`git commit -m ${"chore: first commit"} --allow-empty`;
29+
30+
// add commit for package A
31+
await sandbox.writeFiles({
32+
"package-a/foo.txt": "foo",
33+
});
34+
await sandbox.$`git add package-a/foo.txt`;
35+
await sandbox.$`git commit -m ${"patch: fix foo"}`;
36+
37+
// add commit for package B
38+
await sandbox.writeFiles({
39+
"package-b/bar.txt": "bar",
40+
});
41+
await sandbox.$`git add package-b/bar.txt`;
42+
await sandbox.$`git commit -m ${"feat: add bar"}`;
43+
44+
// versioning
45+
await sandbox.$`${CONVER} version`;
46+
47+
// check version for package A
48+
const pkgA = (await sandbox.readJsoncFile("package-a/package.json")) as {
49+
version?: string;
50+
};
51+
expect(pkgA.version).toBe("1.2.4");
52+
53+
// check version for package B
54+
const pkgB = (await sandbox.readJsoncFile("package-b/package.json")) as {
55+
version?: string;
56+
};
57+
expect(pkgB.version).toBe("1.3.0");
58+
});
59+
});
60+
61+
it("bumps nested packages", async () => {
62+
await sandbox(async (sandbox) => {
63+
// package.json
64+
await sandbox.writeFiles({
65+
"package.json": json({
66+
name: "my-workspace",
67+
version: "0.0.0",
68+
workspaces: ["package-a", "package-a/package-b"],
69+
}),
70+
"package-a/package.json": json({
71+
name: "package-a",
72+
version: "1.2.3",
73+
}),
74+
"package-a/package-b/package.json": json({
75+
name: "package-b",
76+
version: "1.2.3",
77+
}),
78+
});
79+
80+
// init sandbox
81+
await sandbox.$`git init`;
82+
await sandbox.$`${CONVER} init --yes`;
83+
await sandbox.$`git commit -m ${"chore: first commit"} --allow-empty`;
84+
85+
// add commit
86+
await sandbox.writeFiles({
87+
"package-a/package-b/foo.txt": "foo",
88+
});
89+
await sandbox.$`git add package-a/package-b/foo.txt`;
90+
await sandbox.$`git commit -m ${"patch: fix foo"}`;
91+
92+
// versioning
93+
await sandbox.$`${CONVER} version`;
94+
95+
// check version for package A
96+
const pkgA = (await sandbox.readJsoncFile("package-a/package.json")) as {
97+
version?: string;
98+
};
99+
expect(pkgA.version).toBe("1.2.4");
100+
101+
// check version for package B
102+
const pkgB = (await sandbox.readJsoncFile(
103+
"package-a/package-b/package.json",
104+
)) as {
105+
version?: string;
106+
};
107+
expect(pkgB.version).toBe("1.2.4");
108+
});
109+
});

e2e/pre-release.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ it("exists pre-release", async () => {
7777

7878
// check config
7979
const options = (await sandbox.readJsoncFile("conver.json")) as Options;
80-
console.log(options);
8180
expect(Object.keys(options.preReleases ?? {})).not.toContain("my-package");
8281
});
8382
});

e2e/utils/sandbox.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { $, ExecaScriptMethod } from "execa";
22
import { createHash } from "node:crypto";
33
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
4-
import { join, resolve } from "node:path";
4+
import { dirname, join, resolve } from "node:path";
55
import jsonc from "jsonc-parser";
66

77
export default async function sandbox(
@@ -32,7 +32,9 @@ export class Sandbox {
3232

3333
async writeFiles(files: Record<string, string>): Promise<void> {
3434
for (const [name, data] of Object.entries(files)) {
35-
await writeFile(join(this.root, name), data);
35+
const path = join(this.root, name);
36+
await mkdir(dirname(path), { recursive: true });
37+
await writeFile(path, data);
3638
}
3739
}
3840

0 commit comments

Comments
 (0)