/
publish-lifecycle-scripts.test.js
58 lines (48 loc) · 1.93 KB
/
publish-lifecycle-scripts.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
"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 modules
const runLifecycle = require("@lerna/run-lifecycle");
// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
// test command
const lernaPublish = require("@lerna-test/command-runner")(require("../command"));
describe("lifecycle scripts", () => {
it("calls publish lifecycle scripts for root and packages", async () => {
const cwd = await initFixture("lifecycle");
await lernaPublish(cwd)();
expect(runLifecycle).toHaveBeenCalledTimes(12);
["prepare", "prepublishOnly", "postpublish"].forEach(script => {
// "lifecycle" is the root manifest name
expect(runLifecycle).toHaveBeenCalledWith(expect.objectContaining({ name: "lifecycle" }), script);
expect(runLifecycle).toHaveBeenCalledWith(expect.objectContaining({ name: "package-1" }), script);
});
// package-2 lacks version lifecycle scripts
expect(runLifecycle).not.toHaveBeenCalledWith(
expect.objectContaining({ name: "package-2" }),
expect.any(String)
);
expect(runLifecycle.getOrderedCalls()).toEqual([
// TODO: separate from VersionCommand details
["lifecycle", "preversion"],
["package-1", "preversion"],
["package-1", "version"],
["lifecycle", "version"],
["package-1", "postversion"],
["lifecycle", "postversion"],
// publish-specific
["lifecycle", "prepare"],
["lifecycle", "prepublishOnly"],
["package-1", "prepare"],
["package-1", "prepublishOnly"],
["package-1", "postpublish"],
["lifecycle", "postpublish"],
]);
});
});