/
version-github-release.test.js
120 lines (95 loc) · 3.62 KB
/
version-github-release.test.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"use strict";
// local modules _must_ be explicitly mocked
jest.mock("../lib/git-add");
jest.mock("../lib/git-commit");
jest.mock("../lib/git-push");
jest.mock("../lib/git-tag");
jest.mock("../lib/is-anything-committed");
jest.mock("../lib/is-behind-upstream");
jest.mock("../lib/remote-branch-exists");
// mocked modules
const { client } = require("@lerna/github-client");
const { recommendVersion } = require("@lerna/conventional-commits");
// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
// test command
const lernaVersion = require("@lerna-test/command-runner")(require("../command"));
test("--github-release does not create a release if --no-push is passed", async () => {
const cwd = await initFixture("independent");
await lernaVersion(cwd)("--github-release", "--conventional-commits", "--no-push");
expect(client.repos.createRelease).not.toHaveBeenCalled();
});
test("--github-release throws an error if --conventional-commits is not passed", async () => {
const cwd = await initFixture("independent");
try {
await lernaVersion(cwd)("--github-release");
} catch (err) {
expect(err.message).toBe("To create a release, you must enable --conventional-commits");
expect(client.repos.createRelease).not.toHaveBeenCalled();
}
expect.hasAssertions();
});
test("--github-release throws an error if --no-changelog also passed", async () => {
const cwd = await initFixture("independent");
try {
await lernaVersion(cwd)("--github-release", "--conventional-commits", "--no-changelog");
} catch (err) {
expect(err.message).toBe("To create a release, you cannot pass --no-changelog");
expect(client.repos.createRelease).not.toHaveBeenCalled();
}
expect.hasAssertions();
});
test("--github-release marks a version as a pre-release if it contains a valid part", async () => {
const cwd = await initFixture("normal");
recommendVersion.mockResolvedValueOnce("2.0.0-alpha.1");
await lernaVersion(cwd)("--github-release", "--conventional-commits");
expect(client.repos.createRelease).toHaveBeenCalledTimes(1);
expect(client.repos.createRelease).toHaveBeenCalledWith({
owner: "lerna",
repo: "lerna",
tag_name: "v2.0.0-alpha.1",
name: "v2.0.0-alpha.1",
body: "normal",
draft: false,
prerelease: true,
});
});
test("--github-release creates a release for every independent version", async () => {
const cwd = await initFixture("independent");
const versionBumps = new Map([
["package-1", "1.0.1"],
["package-2", "2.1.0"],
["package-3", "4.0.0"],
["package-4", "4.1.0"],
["package-5", "5.0.1"],
]);
versionBumps.forEach(bump => recommendVersion.mockResolvedValueOnce(bump));
await lernaVersion(cwd)("--github-release", "--conventional-commits");
expect(client.repos.createRelease).toHaveBeenCalledTimes(5);
versionBumps.forEach((version, name) => {
expect(client.repos.createRelease).toHaveBeenCalledWith({
owner: "lerna",
repo: "lerna",
tag_name: `${name}@${version}`,
name: `${name}@${version}`,
body: `${name} - ${version}`,
draft: false,
prerelease: false,
});
});
});
test("--github-release creates a single fixed release", async () => {
const cwd = await initFixture("normal");
recommendVersion.mockResolvedValueOnce("1.1.0");
await lernaVersion(cwd)("--github-release", "--conventional-commits");
expect(client.repos.createRelease).toHaveBeenCalledTimes(1);
expect(client.repos.createRelease).toHaveBeenCalledWith({
owner: "lerna",
repo: "lerna",
tag_name: "v1.1.0",
name: "v1.1.0",
body: "normal",
draft: false,
prerelease: false,
});
});