-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
lerna-publish-lifecycle-errors.test.js
67 lines (53 loc) · 2 KB
/
lerna-publish-lifecycle-errors.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
"use strict";
const fs = require("fs-extra");
const path = require("path");
const cliRunner = require("@lerna-test/cli-runner");
const gitAdd = require("@lerna-test/git-add");
const gitCommit = require("@lerna-test/git-commit");
const cloneFixture = require("@lerna-test/clone-fixture")(
path.resolve(__dirname, "../commands/publish/__tests__")
);
const normalizeTestRoot = require("@lerna-test/normalize-test-root");
const env = {
// never actually upload when calling `npm install`
npm_config_dry_run: true,
// skip npm package validation, none of the stubs are real
LERNA_INTEGRATION: "SKIP",
};
test("lerna publish lifecycle scripts stop on non-zero exit", async () => {
const { cwd } = await cloneFixture("lifecycle");
const args = ["publish", "minor", "--yes", "--no-verify-registry"];
const rootManifest = path.join(cwd, "package.json");
const json = await fs.readJson(rootManifest);
json.scripts.preversion = "echo boom && exit 123";
// console.log(json);
await fs.writeJson(rootManifest, json);
await gitAdd(cwd, rootManifest);
await gitCommit(cwd, "update root prepack");
try {
await cliRunner(cwd, env)(...args);
} catch (err) {
expect(err.code).toBe(123);
expect(normalizeTestRoot(err.stdout)).toMatchInlineSnapshot(`
Changes:
- package-1: 1.0.0 => 1.1.0
- package-2: 1.0.0 => 1.1.0
> lifecycle@0.0.0-monorepo preversion __TEST_ROOTDIR__
> echo boom && exit 123
boom
`);
expect(err.stderr).toMatchInlineSnapshot(`
lerna notice cli __TEST_VERSION__
lerna info current version 1.0.0
lerna info Looking for changed packages since initial commit.
lerna info auto-confirmed
lerna info lifecycle lifecycle@0.0.0-monorepo~preversion: lifecycle@0.0.0-monorepo
lerna info lifecycle lifecycle@0.0.0-monorepo~preversion: Failed to exec preversion script
lerna ERR! lifecycle "preversion" errored in "lifecycle", ejecting
lerna ERR! exited 123 in 'lifecycle'
lerna ERR! exited 123 in 'lifecycle'
lerna ERR! exited 123 in 'lifecycle'
lerna ERR! exited 123 in 'lifecycle'
`);
}
});