/
version-bump-prerelease.test.js
235 lines (191 loc) · 6.63 KB
/
version-bump-prerelease.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
"use strict";
// we're actually testing integration with git
jest.unmock("@lerna/collect-updates");
jest.unmock("@lerna/conventional-commits");
// local modules _must_ be explicitly mocked
jest.mock("../lib/git-push");
jest.mock("../lib/is-anything-committed");
jest.mock("../lib/is-behind-upstream");
jest.mock("../lib/remote-branch-exists");
const fs = require("fs-extra");
const path = require("path");
// mocked modules
const prompt = require("@lerna/prompt");
// helpers
const initFixture = require("@lerna-test/init-fixture")(path.resolve(__dirname, "../../publish/__tests__"));
const showCommit = require("@lerna-test/show-commit");
const gitInit = require("@lerna-test/git-init");
const gitAdd = require("@lerna-test/git-add");
const gitTag = require("@lerna-test/git-tag");
const gitCommit = require("@lerna-test/git-commit");
const getCommitMessage = require("@lerna-test/get-commit-message");
const Tacks = require("tacks");
const tempy = require("tempy");
const { File, Dir } = Tacks;
// test command
const lernaVersion = require("@lerna-test/command-runner")(require("../command"));
// remove quotes around top-level strings
expect.addSnapshotSerializer({
test(val) {
return typeof val === "string";
},
serialize(val, config, indentation, depth) {
// top-level strings don't need quotes, but nested ones do (object properties, etc)
return depth ? `"${val}"` : val;
},
});
// stabilize commit SHA
expect.addSnapshotSerializer(require("@lerna-test/serialize-changelog"));
const setupChanges = async cwd => {
await gitTag(cwd, "v1.0.1-beta.3");
await fs.outputFile(path.join(cwd, "packages/package-3/hello.js"), "world");
await gitAdd(cwd, ".");
await gitCommit(cwd, "feat: setup");
};
test("version patch with previous prerelease also graduates prereleased", async () => {
const testDir = await initFixture("republish-prereleased");
// should republish 3, 4, and 5 because:
// package 3 changed
// package 5 has a prerelease version
// package 4 depends on package 5
await setupChanges(testDir);
await lernaVersion(testDir)("patch");
const patch = await showCommit(testDir);
expect(patch).toMatchSnapshot();
});
test("version prerelease with previous prerelease bumps changed only", async () => {
const testDir = await initFixture("republish-prereleased");
// should republish only package 3, because only it changed
await setupChanges(testDir);
await lernaVersion(testDir)("prerelease");
const patch = await showCommit(testDir);
expect(patch).toMatchSnapshot();
});
test("version prerelease with previous prerelease supersedes --conventional-commits", async () => {
const testDir = await initFixture("republish-prereleased");
// version bump should stay prepatch --preid beta because ---conventional-commits is ignored
await setupChanges(testDir);
await lernaVersion(testDir)("prerelease", "--conventional-commits");
const patch = await showCommit(testDir);
expect(patch).toMatchSnapshot();
});
test("version prerelease with existing preid bumps with the preid provide as argument", async () => {
const testDir = await initFixture("republish-prereleased");
// Version bump should have the new rc preid
await setupChanges(testDir);
await lernaVersion(testDir)("prerelease", "--preid", "rc");
const message = await getCommitMessage(testDir);
expect(message).toBe("v1.0.1-rc.0");
});
test("version prerelease with immediate graduation", async () => {
const testDir = await initFixture("republish-prereleased");
await setupChanges(testDir);
await lernaVersion(testDir)("prerelease", "--force-publish", "package-4");
// package-4 had no changes, but should still be included for some mysterious reason
const firstDiff = await showCommit(testDir);
expect(firstDiff).toMatchSnapshot();
// no changes, but force everything because the previous prerelease passed QA
await lernaVersion(testDir)("patch", "--force-publish");
const secondDiff = await showCommit(testDir);
expect(secondDiff).toMatchSnapshot();
});
test("independent version prerelease does not bump on every unrelated change", async () => {
const cwd = tempy.directory();
const fixture = new Tacks(
Dir({
"lerna.json": File({
version: "independent",
}),
"package.json": File({
name: "unrelated-bumps",
}),
packages: Dir({
"pkg-a": Dir({
"package.json": File({
name: "pkg-a",
version: "1.0.0",
}),
}),
"pkg-b": Dir({
"package.json": File({
name: "pkg-b",
version: "1.0.0-bumps.1",
// TODO: (major) make --no-private the default
private: true,
}),
}),
}),
})
);
fixture.create(cwd);
await gitInit(cwd, ".");
await gitAdd(cwd, "-A");
await gitCommit(cwd, "init");
// simulate choices for pkg-a then pkg-b
prompt.mockChoices("patch", "PRERELEASE");
prompt.input.mockImplementationOnce((msg, cfg) =>
// the _existing_ "bumps" prerelease ID should be preserved
Promise.resolve(cfg.filter())
);
await lernaVersion(cwd)();
const first = await getCommitMessage(cwd);
expect(first).toMatchInlineSnapshot(`
Publish
- pkg-a@1.0.1
- pkg-b@1.0.0-bumps.2
`);
await fs.outputFile(path.join(cwd, "packages/pkg-a/hello.js"), "world");
await gitAdd(cwd, ".");
await gitCommit(cwd, "feat: hello world");
// all of this just to say...
await lernaVersion(cwd)();
const second = await getCommitMessage(cwd);
expect(second).toMatchInlineSnapshot(`
Publish
- pkg-a@1.0.2
`);
});
test("independent version prerelease respects --no-private", async () => {
const cwd = tempy.directory();
const fixture = new Tacks(
Dir({
"lerna.json": File({
version: "independent",
}),
"package.json": File({
name: "no-private-versioning",
}),
packages: Dir({
"pkg-1": Dir({
"package.json": File({
name: "pkg-1",
version: "1.0.0",
devDependencies: {
"pkg-2": "^2.0.0",
},
}),
}),
"pkg-2": Dir({
"package.json": File({
name: "pkg-2",
version: "2.0.0",
private: true,
}),
}),
}),
})
);
fixture.create(cwd);
await gitInit(cwd, ".");
await gitAdd(cwd, "-A");
await gitCommit(cwd, "init");
// TODO: (major) make --no-private the default
await lernaVersion(cwd)("prerelease", "--no-private");
const changedFiles = await showCommit(cwd, "--name-only");
expect(changedFiles).toMatchInlineSnapshot(`
Publish
- pkg-1@1.0.1-alpha.0
HEAD -> master, tag: pkg-1@1.0.1-alpha.0
packages/pkg-1/package.json
`);
});