/
publish-command.test.js
167 lines (131 loc) · 4.78 KB
/
publish-command.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
"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/verify-npm-registry");
// 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");
// mocked or stubbed modules
const npmDistTag = require("@lerna/npm-dist-tag");
const npmPublish = require("@lerna/npm-publish");
// helpers
const loggingOutput = require("@lerna-test/logging-output");
const gitTag = require("@lerna-test/git-tag");
const initFixture = require("@lerna-test/init-fixture")(__dirname);
// file under test
const lernaPublish = require("@lerna-test/command-runner")(require("../command"));
describe("PublishCommand", () => {
describe("with implied versioning", () => {
it("publishes changed packages", async () => {
const testDir = await initFixture("normal");
await lernaPublish(testDir)();
expect(npmPublish.order()).toEqual([
"package-1",
"package-3",
"package-4",
"package-2",
// package-5 is private
]);
expect(npmDistTag.check).not.toBeCalled();
expect(npmDistTag.remove).not.toBeCalled();
expect(npmDistTag.add).not.toBeCalled();
});
it("publishes changed independent packages", async () => {
const testDir = await initFixture("independent");
await lernaPublish(testDir)();
expect(npmPublish.order()).toEqual([
"package-1",
"package-3",
"package-4",
"package-2",
// package-5 is private
]);
});
it("--skip-npm yields immediately to VersionCommand with warning", async () => {
const cwd = await initFixture("normal");
await lernaPublish(cwd)("--skip-npm");
expect(npmPublish.order()).toHaveLength(0);
const logMessages = loggingOutput("warn");
expect(logMessages).toContain("Instead of --skip-npm, call `lerna version` directly");
});
it("throws an error in fixed mode when --independent is passed", async () => {
const testDir = await initFixture("normal");
try {
await lernaPublish(testDir)("--independent");
} catch (err) {
expect(err.message).toMatch("independent");
}
expect.assertions(1);
});
});
describe("from-git", () => {
it("publishes tagged packages", async () => {
const testDir = await initFixture("normal");
await gitTag(testDir, "v1.0.0");
await lernaPublish(testDir)("from-git");
expect(npmPublish.order()).toEqual([
"package-1",
"package-3",
"package-4",
"package-2",
// package-5 is private
]);
});
it("publishes tagged independent packages", async () => {
const testDir = await initFixture("independent");
await Promise.all([
gitTag(testDir, "package-1@1.0.0"),
gitTag(testDir, "package-2@2.0.0"),
gitTag(testDir, "package-3@3.0.0"),
gitTag(testDir, "package-4@4.0.0"),
gitTag(testDir, "package-5@5.0.0"),
]);
await lernaPublish(testDir)("from-git");
expect(npmPublish.order()).toEqual([
"package-1",
"package-3",
"package-4",
"package-2",
// package-5 is private
]);
});
it("only publishes independent packages with matching tags", async () => {
const testDir = await initFixture("independent");
await gitTag(testDir, "package-3@3.0.0");
await lernaPublish(testDir)("from-git");
expect(npmPublish.order()).toEqual(["package-3"]);
});
it("exits early when the current commit is not tagged", async () => {
const testDir = await initFixture("normal");
await lernaPublish(testDir)("from-git");
expect(npmPublish).not.toBeCalled();
const logMessages = loggingOutput("info");
expect(logMessages).toContain("No tagged release found");
});
});
describe("--registry", () => {
it("passes registry to npm commands", async () => {
const testDir = await initFixture("normal");
const registry = "https://my-private-registry";
await lernaPublish(testDir)("--registry", registry);
expect(npmPublish).toBeCalledWith(
expect.objectContaining({ name: "package-1" }),
undefined, // dist-tag
expect.objectContaining({ registry })
);
});
});
describe("in a cyclical repo", () => {
it("should throw an error with --reject-cycles", async () => {
expect.assertions(1);
try {
const testDir = await initFixture("toposort");
await lernaPublish(testDir)("--reject-cycles");
} catch (err) {
expect(err.message).toMatch("Dependency cycles detected, you should fix these!");
}
});
});
});