/
publish-tagging.test.js
169 lines (125 loc) · 4.98 KB
/
publish-tagging.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
"use strict";
// local modules _must_ be explicitly mocked
jest.mock("../lib/get-packages-without-license");
jest.mock("../lib/verify-npm-package-access");
jest.mock("../lib/get-npm-username");
// FIXME: better mock for version command
jest.mock("../../version/lib/git-push");
jest.mock("../../version/lib/is-anything-committed");
jest.mock("../../version/lib/is-behind-upstream");
jest.mock("../../version/lib/remote-branch-exists");
// mocked modules
const collectUpdates = require("@lerna/collect-updates");
const npmDistTag = require("@lerna/npm-dist-tag");
const npmPublish = require("@lerna/npm-publish");
// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
// test command
const lernaPublish = require("@lerna-test/command-runner")(require("../command"));
test("publish --dist-tag next", async () => {
const cwd = await initFixture("normal");
collectUpdates.setUpdated(cwd, "package-1");
await lernaPublish(cwd)("--dist-tag", "next");
expect(npmPublish.registry.get("package-1")).toBe("next");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});
test("publish --dist-tag nightly --canary", async () => {
const cwd = await initFixture("normal");
collectUpdates.setUpdated(cwd, "package-2");
await lernaPublish(cwd)("--dist-tag", "nightly", "--canary");
expect(npmPublish.registry.get("package-2")).toBe("nightly");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});
test("publish --npm-tag deprecated", async () => {
const cwd = await initFixture("normal");
collectUpdates.setUpdated(cwd, "package-3");
await lernaPublish(cwd)("--npm-tag", "deprecated");
expect(npmPublish.registry.get("package-3")).toBe("deprecated");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});
test("publish --temp-tag", async () => {
const cwd = await initFixture("integration");
await lernaPublish(cwd)("--temp-tag");
expect(npmPublish.registry).toMatchInlineSnapshot(`
Map {
"@integration/package-1" => "lerna-temp",
"@integration/package-2" => "lerna-temp",
}
`);
const conf = expect.objectContaining({
tag: "latest",
});
const cache = expect.objectContaining({
otp: undefined,
});
expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-1@1.0.1", "lerna-temp", conf, cache);
expect(npmDistTag.remove).toHaveBeenCalledWith("@integration/package-2@1.0.1", "lerna-temp", conf, cache);
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "CUSTOM", conf, cache); // <--
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "latest", conf, cache);
});
test("publish --dist-tag beta --temp-tag", async () => {
const cwd = await initFixture("integration");
await lernaPublish(cwd)("--dist-tag", "beta", "--temp-tag");
expect(npmPublish.registry).toMatchInlineSnapshot(`
Map {
"@integration/package-1" => "lerna-temp",
"@integration/package-2" => "lerna-temp",
}
`);
const conf = expect.objectContaining({
tag: "beta",
});
const cache = expect.objectContaining({
otp: undefined,
});
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1", "beta", conf, cache); // <--
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1", "beta", conf, cache);
});
test("publish prerelease --pre-dist-tag beta", async () => {
const cwd = await initFixture("normal");
collectUpdates.setUpdated(cwd, "package-1");
await lernaPublish(cwd)("prerelease", "--pre-dist-tag", "beta");
expect(npmPublish.registry.get("package-1")).toBe("beta");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});
test("publish non-prerelease --pre-dist-tag beta", async () => {
const cwd = await initFixture("normal");
collectUpdates.setUpdated(cwd, "package-1");
await lernaPublish(cwd)("--pre-dist-tag", "beta");
expect(npmPublish.registry.get("package-1")).toBe("latest");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});
test("publish non-prerelease --dist-tag next --pre-dist-tag beta", async () => {
const cwd = await initFixture("normal");
collectUpdates.setUpdated(cwd, "package-1");
await lernaPublish(cwd)("--dist-tag", "next", "--pre-dist-tag", "beta");
expect(npmPublish.registry.get("package-1")).toBe("next");
expect(npmDistTag.remove).not.toHaveBeenCalled();
});
test("publish --pre-dist-tag beta --temp-tag", async () => {
const cwd = await initFixture("integration");
await lernaPublish(cwd)(
"prerelease",
"--dist-tag",
"next",
"--preid",
"beta",
"--pre-dist-tag",
"beta",
"--temp-tag"
);
expect(npmPublish.registry).toMatchInlineSnapshot(`
Map {
"@integration/package-1" => "lerna-temp",
"@integration/package-2" => "lerna-temp",
}
`);
const conf = expect.objectContaining({
tag: "next",
});
const cache = expect.objectContaining({
otp: undefined,
});
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-1@1.0.1-beta.0", "beta", conf, cache);
expect(npmDistTag.add).toHaveBeenCalledWith("@integration/package-2@1.0.1-beta.0", "beta", conf, cache);
});