/
publish-relative-file-specifiers.test.js
119 lines (98 loc) · 3.8 KB
/
publish-relative-file-specifiers.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
"use strict";
// we're actually testing integration with git
jest.unmock("@lerna/collect-updates");
// 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");
const fs = require("fs-extra");
const path = require("path");
// mocked modules
const writePkg = require("write-pkg");
// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const gitAdd = require("@lerna-test/git-add");
const gitTag = require("@lerna-test/git-tag");
const gitCommit = require("@lerna-test/git-commit");
// test command
const lernaPublish = require("@lerna-test/command-runner")(require("../command"));
describe("relative 'file:' specifiers", () => {
const setupChanges = async (cwd, pkgRoot = "packages") => {
await gitTag(cwd, "v1.0.0");
await fs.outputFile(path.join(cwd, `${pkgRoot}/package-1/hello.js`), "world");
await gitAdd(cwd, ".");
await gitCommit(cwd, "setup");
};
it("overwrites relative link with local version before npm publish but after git commit", async () => {
const cwd = await initFixture("relative-file-specs");
await setupChanges(cwd);
await lernaPublish(cwd)("major", "--yes");
expect(writePkg.updatedVersions()).toEqual({
"package-1": "2.0.0",
"package-2": "2.0.0",
"package-3": "2.0.0",
"package-4": "2.0.0",
"package-5": "2.0.0",
"package-6": "2.0.0",
"package-7": "2.0.0",
});
// notably missing is package-1, which has no relative file: dependencies
expect(writePkg.updatedManifest("package-2").dependencies).toMatchObject({
"package-1": "^2.0.0",
});
expect(writePkg.updatedManifest("package-3").dependencies).toMatchObject({
"package-2": "^2.0.0",
});
expect(writePkg.updatedManifest("package-4").optionalDependencies).toMatchObject({
"package-3": "^2.0.0",
});
expect(writePkg.updatedManifest("package-5").dependencies).toMatchObject({
"package-4": "^2.0.0",
// all fixed versions are bumped when major
"package-6": "^2.0.0",
});
// private packages do not need local version resolution
expect(writePkg.updatedManifest("package-7").dependencies).toMatchObject({
"package-1": "file:../package-1",
});
});
it("falls back to existing relative version when it is not updated", async () => {
const cwd = await initFixture("relative-independent");
await setupChanges(cwd);
await lernaPublish(cwd)("minor", "--yes");
expect(writePkg.updatedVersions()).toEqual({
"package-1": "1.1.0",
"package-2": "2.1.0",
"package-3": "3.1.0",
"package-4": "4.1.0",
"package-5": "5.1.0",
});
// package-4 was updated, but package-6 was not
expect(writePkg.updatedManifest("package-5").dependencies).toMatchObject({
"package-4": "^4.1.0",
"package-6": "^6.0.0",
});
});
it("respects --exact", async () => {
const cwd = await initFixture("relative-independent");
await setupChanges(cwd);
await lernaPublish(cwd)("patch", "--yes", "--exact");
// package-4 was updated, but package-6 was not
expect(writePkg.updatedManifest("package-5").dependencies).toMatchObject({
"package-4": "4.0.1",
"package-6": "6.0.0",
});
});
it("works around npm-incompatible link: specifiers", async () => {
const cwd = await initFixture("yarn-link-spec");
await setupChanges(cwd, "workspaces");
await lernaPublish(cwd)("major", "--yes");
expect(writePkg.updatedManifest("package-2").dependencies).toMatchObject({
"package-1": "^2.0.0",
});
});
});