-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
lerna-bootstrap.test.js
103 lines (87 loc) · 3.2 KB
/
lerna-bootstrap.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
"use strict";
const fs = require("fs-extra");
const globby = require("globby");
const normalizePath = require("normalize-path");
const cliRunner = require("@lerna-test/cli-runner");
const initFixture = require("@lerna-test/init-fixture")(__dirname);
describe("lerna bootstrap", () => {
test("bootstraps all packages", async () => {
const cwd = await initFixture("lerna-bootstrap");
const lerna = cliRunner(cwd);
const { stderr } = await lerna("bootstrap");
expect(stderr).toMatchSnapshot("stderr");
// the "--silent" flag is passed to `npm run`
const { stdout } = await lerna("run", "test", "--", "--silent");
expect(stdout).toMatchSnapshot("stdout");
const lockfiles = await globby(["package-*/package-lock.json"], { cwd, absolute: true });
const [lock1, lock2, lock3] = await Promise.all(lockfiles.sort().map(fp => fs.readJson(fp)));
expect(lock1).toMatchObject({
name: "@integration/package-1",
version: "1.0.0",
dependencies: {
pify: expect.any(Object),
"tiny-tarball": {
version: "1.0.0",
optional: true,
},
},
});
expect(lock2).toMatchObject({
name: "@integration/package-2",
version: "1.0.0",
dependencies: { pify: expect.any(Object) },
});
expect(lock3).toMatchObject({
name: "@integration/package-3",
version: "1.0.0",
dependencies: { pify: expect.any(Object) },
});
});
test("hoists correctly", async () => {
const cwd = await initFixture("lerna-bootstrap");
const lerna = cliRunner(cwd);
const { stderr } = await lerna("bootstrap", "--hoist");
expect(stderr).toMatchSnapshot("stderr");
// the "--silent" flag is passed to `npm run`
const { stdout } = await lerna("run", "test", "--", "--silent");
expect(stdout).toMatchSnapshot("stdout");
const lockfiles = await globby(["**/package-lock.json"], {
cwd,
absolute: true,
followSymlinkedDirectories: false,
});
const [lock3, rootLock] = await Promise.all(lockfiles.sort().map(fp => fs.readJson(fp)));
expect(lock3).toMatchObject({
name: "@integration/package-3",
version: "1.0.0",
dependencies: { pify: expect.any(Object) },
});
expect(rootLock).toMatchObject({
name: "integration",
version: "0.0.0",
dependencies: {
pify: expect.any(Object),
"tiny-tarball": {
version: "1.0.0",
// root hoist does not preserve optional
},
},
});
expect(rootLock).not.toHaveProperty("dependencies.tiny-tarball.optional");
});
test("--npm-client yarn", async () => {
const cwd = await initFixture("lerna-bootstrap");
const lerna = cliRunner(cwd);
const { stderr } = await lerna("bootstrap", "--npm-client", "yarn");
expect(stderr).toMatchSnapshot("stderr");
const lockfiles = await globby(["package-*/yarn.lock"], { cwd });
expect(lockfiles.sort().map(fp => normalizePath(fp))).toEqual([
"package-1/yarn.lock",
"package-2/yarn.lock",
"package-3/yarn.lock",
]);
// the "--silent" flag is passed to `npm run`
const { stdout } = await lerna("run", "test", "--", "--silent");
expect(stdout).toMatchSnapshot("stdout");
});
});