/
lerna-run-nx-include-dependencies.spec.ts
320 lines (220 loc) · 9.45 KB
/
lerna-run-nx-include-dependencies.spec.ts
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import { remove } from "fs-extra";
import { Fixture } from "../../utils/fixture";
import { normalizeCommandOutput, normalizeEnvironment } from "../../utils/snapshot-serializer-utils";
expect.addSnapshotSerializer({
serialize(str: string) {
return normalizeCommandOutput(normalizeEnvironment(str));
},
test(val: string) {
return val != null && typeof val === "string";
},
});
describe("lerna-run-nx-include-dependencies", () => {
let fixture: Fixture;
beforeEach(async () => {
fixture = await Fixture.create({
name: "lerna-run-nx-include-dependencies",
packageManager: "npm",
initializeGit: true,
runLernaInit: true,
installDependencies: true,
/**
* Because lerna run involves spawning further child processes, the tests would be too flaky
* if we didn't force deterministic terminal output by appending stderr to stdout instead
* of interleaving them.
*/
forceDeterministicTerminalOutput: true,
});
await fixture.lerna("create package-1 -y");
await fixture.addScriptsToPackage({
packagePath: "packages/package-1",
scripts: {
"print-name": "echo test-package-1",
},
});
await fixture.lerna("create package-2 -y");
await fixture.addScriptsToPackage({
packagePath: "packages/package-2",
scripts: {
"print-name": "echo test-package-2",
},
});
await fixture.lerna("create package-3 -y --dependencies package-1 package-2");
await fixture.addScriptsToPackage({
packagePath: "packages/package-3",
scripts: {
"print-name": "echo test-package-3",
},
});
await fixture.updateJson("lerna.json", (json) => ({
...json,
loglevel: "verbose",
}));
});
afterEach(() => fixture.destroy());
describe("without nx enabled", () => {
it("should exclude dependencies by default", async () => {
// Enable legacy task runner
await fixture.overrideLernaConfig({
useNx: false,
});
const output = await fixture.lerna("run print-name --scope package-3 -- --silent");
expect(output.combinedOutput).toMatchInlineSnapshot(`
test-package-X
lerna notice cli v999.9.9-e2e.0
lerna verb rootPath /tmp/lerna-e2e/lerna-run-nx-include-dependencies/lerna-workspace
lerna notice filter including "package-X"
lerna info filter [ 'package-X' ]
lerna info Executing command in 1 package: "npm run print-name --silent"
lerna info run Ran npm script 'print-name' in 'package-X' in X.Xs:
lerna success run Ran npm script 'print-name' in 1 package in X.Xs:
lerna success - package-X
`);
});
});
describe("with nx enabled, but no nx.json", () => {
it("should exclude dependencies by default", async () => {
await fixture.addNxJsonToWorkspace();
await remove(fixture.getWorkspacePath("nx.json"));
const output = await fixture.lerna("run print-name --scope package-3 -- --silent");
expect(output.combinedOutput).toMatchInlineSnapshot(`
> package-X:print-name --silent
> package-X@0.0.0 print-name
> echo test-package-X "--silent"
test-package-X --silent
> Lerna (powered by Nx) Successfully ran target print-name for project package-X
lerna notice cli v999.9.9-e2e.0
lerna verb rootPath /tmp/lerna-e2e/lerna-run-nx-include-dependencies/lerna-workspace
lerna notice filter including "package-X"
lerna info filter [ 'package-X' ]
lerna verb run nx.json was not found or is missing targetDefaults. Task dependencies will not be automatically included.
`);
});
});
describe("with nx enabled and with nx.json without targetDefaults", () => {
it("should exclude dependencies by default", async () => {
await fixture.addNxJsonToWorkspace();
const output = await fixture.lerna("run print-name --scope package-3 -- --silent");
expect(output.combinedOutput).toMatchInlineSnapshot(`
> package-X:print-name --silent
> package-X@0.0.0 print-name
> echo test-package-X "--silent"
test-package-X --silent
> Lerna (powered by Nx) Successfully ran target print-name for project package-X
lerna notice cli v999.9.9-e2e.0
lerna verb rootPath /tmp/lerna-e2e/lerna-run-nx-include-dependencies/lerna-workspace
lerna notice filter including "package-X"
lerna info filter [ 'package-X' ]
lerna verb run nx.json was not found or is missing targetDefaults. Task dependencies will not be automatically included.
`);
});
});
describe("with nx enabled and with nx.json with targetDefaults", () => {
it("should include package dependencies by default", async () => {
await fixture.addNxJsonToWorkspace();
await fixture.updateJson("nx.json", (json) => ({
...json,
targetDefaults: {
"print-name": {
dependsOn: ["^print-name"],
},
},
}));
const output = await fixture.lerna("run print-name --scope package-3");
expect(output.combinedOutput).toMatchInlineSnapshot(`
> Lerna (powered by Nx) Running target print-name for project package-X and 2 task(s) it depends on
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> Lerna (powered by Nx) Successfully ran target print-name for project package-X
lerna notice cli v999.9.9-e2e.0
lerna verb rootPath /tmp/lerna-e2e/lerna-run-nx-include-dependencies/lerna-workspace
lerna notice filter including "package-X"
lerna info filter [ 'package-X' ]
lerna verb run nx.json with targetDefaults was found. Task dependencies will be automatically included.
`);
});
it("should include package dependencies with --include-dependencies", async () => {
await fixture.addNxJsonToWorkspace();
await fixture.updateJson("nx.json", (json) => ({
...json,
targetDefaults: {
"print-name": {
dependsOn: ["^print-name"],
},
},
}));
const output = await fixture.lerna("run print-name --scope package-3 --include-dependencies");
expect(output.combinedOutput).toMatchInlineSnapshot(`
> Lerna (powered by Nx) Running target print-name for 3 project(s):
- package-X
- package-X
- package-X
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> Lerna (powered by Nx) Successfully ran target print-name for 3 projects
lerna notice cli v999.9.9-e2e.0
lerna verb rootPath /tmp/lerna-e2e/lerna-run-nx-include-dependencies/lerna-workspace
lerna notice filter including "package-X"
lerna notice filter including dependencies
lerna info filter [ 'package-X' ]
lerna verb run nx.json with targetDefaults was found. Task dependencies will be automatically included.
lerna info run Using the "include-dependencies" option when nx.json has targetDefaults defined will include both task dependencies detected by Nx and project dependencies detected by Lerna. See https://lerna.js.org/docs/lerna6-obsolete-options#--include-dependencies for details.
`);
});
it("with --ignore should still include dependencies", async () => {
await fixture.addNxJsonToWorkspace();
await fixture.updateJson("nx.json", (json) => ({
...json,
targetDefaults: {
"print-name": {
dependsOn: ["^print-name"],
},
},
}));
const output = await fixture.lerna("run print-name --scope package-3 --ignore package-1");
expect(output.combinedOutput).toMatchInlineSnapshot(`
> Lerna (powered by Nx) Running target print-name for project package-X and 2 task(s) it depends on
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> package-X:print-name
> package-X@0.0.0 print-name
> echo test-package-X
test-package-X
> Lerna (powered by Nx) Successfully ran target print-name for project package-X
lerna notice cli v999.9.9-e2e.0
lerna verb rootPath /tmp/lerna-e2e/lerna-run-nx-include-dependencies/lerna-workspace
lerna notice filter including "package-X"
lerna notice filter excluding "package-X"
lerna info filter [ 'package-X', '!package-X' ]
lerna verb run nx.json with targetDefaults was found. Task dependencies will be automatically included.
lerna info run Using the "ignore" option when nx.json has targetDefaults defined will exclude only tasks that are not determined to be required by Nx. See https://lerna.js.org/docs/lerna6-obsolete-options#--ignore for details.
`);
});
});
});