Skip to content

Commit 1b68266

Browse files
Updated all file tests for v5.0
1 parent e2e3894 commit 1b68266

1 file changed

Lines changed: 74 additions & 52 deletions

File tree

test/specs/files.spec.js

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22

3-
const { check, files, fixtures, bump } = require("../utils");
3+
const { check, info, files, fixtures, bump } = require("../utils");
44
const { expect } = require("chai");
55

6-
describe.skip("bump [files...]", () => {
6+
describe("bump [files...]", () => {
77

88
it("should update the package.json and package-lock.json by default", () => {
99
files.create("package.json", { version: "1.2.3" });
@@ -19,26 +19,61 @@ describe.skip("bump [files...]", () => {
1919
`${check} Updated package-lock.json to 2.0.0\n`
2020
);
2121

22-
expect(files.json("package.json").version).to.equal("2.0.0");
23-
expect(files.json("package-lock.json").version).to.equal("2.0.0");
22+
expect(files.json("package.json")).to.deep.equal({ version: "2.0.0" });
23+
expect(files.json("package-lock.json")).to.deep.equal({ version: "2.0.0" });
24+
});
25+
26+
it("should not update package-lock.json if package.json is explicitly specified", () => {
27+
files.create("package.json", { version: "1.2.3" });
28+
files.create("package-lock.json", { version: "1.2.3" });
29+
30+
let cli = bump("major package.json");
31+
32+
expect(cli).to.have.stderr("");
33+
expect(cli).to.have.exitCode(0);
34+
35+
expect(cli).to.have.stdout(
36+
`${check} Updated package.json to 2.0.0\n`
37+
);
38+
39+
expect(files.json("package.json")).to.deep.equal({ version: "2.0.0" });
40+
expect(files.json("package-lock.json")).to.deep.equal({ version: "1.2.3" });
2441
});
2542

2643
it("should not update package.json if package-lock.json is explicitly specified", () => {
2744
files.create("package.json", { version: "1.2.3" });
2845
files.create("package-lock.json", { version: "1.2.3" });
2946

30-
let cli = bump("major");
47+
let cli = bump("major package-lock.json");
3148

3249
expect(cli).to.have.stderr("");
3350
expect(cli).to.have.exitCode(0);
3451

3552
expect(cli).to.have.stdout(
36-
`${check} Updated package.json to 2.0.0\n` +
3753
`${check} Updated package-lock.json to 2.0.0\n`
3854
);
3955

40-
expect(files.json("package.json").version).to.equal("2.0.0");
41-
expect(files.json("package-lock.json").version).to.equal("2.0.0");
56+
expect(files.json("package.json")).to.deep.equal({ version: "1.2.3" });
57+
expect(files.json("package-lock.json")).to.deep.equal({ version: "2.0.0" });
58+
});
59+
60+
it("should not update package.json or package-lock.json if another file is explicitly specified", () => {
61+
files.create("package.json", { version: "1.2.3" });
62+
files.create("package-lock.json", { version: "1.2.3" });
63+
files.create("bower.json", { version: "1.2.3" });
64+
65+
let cli = bump("major bower.json");
66+
67+
expect(cli).to.have.stderr("");
68+
expect(cli).to.have.exitCode(0);
69+
70+
expect(cli).to.have.stdout(
71+
`${check} Updated bower.json to 2.0.0\n`
72+
);
73+
74+
expect(files.json("package.json")).to.deep.equal({ version: "1.2.3" });
75+
expect(files.json("package-lock.json")).to.deep.equal({ version: "1.2.3" });
76+
expect(files.json("bower.json")).to.deep.equal({ version: "2.0.0" });
4277
});
4378

4479
it("should replace the version number in non-manifest files", () => {
@@ -58,15 +93,21 @@ describe.skip("bump [files...]", () => {
5893
expect(cli).to.have.stdout(
5994
`${check} Updated LICENSE to 2.0.0\n` +
6095
`${check} Updated README.md to 2.0.0\n` +
61-
`${check} Updated script1.js to 2.0.0\n`
96+
`${check} Updated script1.js to 2.0.0\n` +
97+
`${info} script2.js did not need to be updated\n` +
98+
`${check} Updated subdir/deep/script1.js to 2.0.0\n` +
99+
`${info} subdir/deep/script2.js did not need to be updated\n`
62100
);
63101

64-
expect(files.json("package.json").version).to.equal("2.0.0");
102+
expect(files.json("package.json")).to.deep.equal({ version: "1.2.3" });
65103
expect(files.text("LICENSE")).to.match(/MyApp v2.0.0 Copyright/);
66104
expect(files.text("README.md")).to.match(/version 2.0.0 and v2.0.0 should both get updated/);
67-
expect(files.text("script1.js")).to.match(/make sure v2.0.0 gets replaced correctly/);
68-
expect(files.text("script1.js")).to.match(/let version = "2.0.0";/);
105+
expect(files.text("script1.js")).to.match(/make sure v2.0.0 gets replaced/);
69106
expect(files.text("script1.js")).to.match(/let version = "2.0.0";/);
107+
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
108+
expect(files.text("subdir/deep/script1.js")).to.match(/make sure v2.0.0 gets replaced/);
109+
expect(files.text("subdir/deep/script1.js")).to.match(/let version = "2.0.0";/);
110+
expect(files.text("subdir/deep/script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
70111
});
71112

72113
it("should not replace other version fields in manifest files", () => {
@@ -83,13 +124,12 @@ describe.skip("bump [files...]", () => {
83124
`${check} Updated package-lock.json to 2.0.0\n`
84125
);
85126

86-
expect(files.text("README.md")).to.match(/version 5.6.7 and v8.9.10 should not be changed/);
87-
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
127+
expect(files.json("package.json")).to.deep.equal({ version: "2.0.0", notTheVersion: "1.2.3" });
128+
expect(files.json("package-lock.json")).to.deep.equal({ version: "2.0.0", notTheVersion: "1.2.3" });
88129
});
89130

90131
it("should not replace other version numbers in non-manifest files", () => {
91132
files.create("package.json", { version: "1.2.3" });
92-
files.create("package-lock.json", { version: "1.2.3" });
93133
files.create("LICENSE", fixtures.license);
94134
files.create("README.md", fixtures.readme);
95135
files.create("script1.js", fixtures.script1);
@@ -101,12 +141,13 @@ describe.skip("bump [files...]", () => {
101141
expect(cli).to.have.exitCode(0);
102142

103143
expect(cli).to.have.stdout(
104-
`${check} Updated package.json to 2.0.0\n` +
144+
`${check} Updated LICENSE to 2.0.0\n` +
105145
`${check} Updated README.md to 2.0.0\n` +
106146
`${check} Updated script1.js to 2.0.0\n` +
107-
`${check} Updated LICENSE to 2.0.0\n`
147+
`${info} script2.js did not need to be updated\n`
108148
);
109149

150+
expect(files.text("LICENSE")).to.match(/MyApp v2.0.0 Copyright/);
110151
expect(files.text("README.md")).to.match(/version 5.6.7 and v8.9.10 should not be changed/);
111152
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
112153
});
@@ -124,61 +165,42 @@ describe.skip("bump [files...]", () => {
124165
expect(cli).to.have.exitCode(0);
125166

126167
expect(cli).to.have.stdout(
127-
`${check} Updated package.json to 5.0.0\n`
168+
`${info} LICENSE did not need to be updated\n` +
169+
`${info} README.md did not need to be updated\n` +
170+
`${info} script1.js did not need to be updated\n` +
171+
`${info} script2.js did not need to be updated\n`
128172
);
129173

130-
expect(files.json("package.json").version).to.equal("5.0.0");
174+
expect(files.json("package.json")).to.deep.equal({ version: "4.5.6" });
131175
expect(files.text("LICENSE")).to.match(/MyApp v1.2.3 Copyright/);
132176
expect(files.text("README.md")).to.match(/version 5.6.7 and v8.9.10 should not be changed/);
133177
expect(files.text("README.md")).to.match(/version 1.2.3 and v1.2.3 should both get updated/);
134-
expect(files.text("script1.js")).to.match(/make sure v1.2.3 gets replaced correctly/);
178+
expect(files.text("script1.js")).to.match(/make sure v1.2.3 gets replaced/);
135179
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
136180
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
137181
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
138182
});
139183

140184
it("should error if an explicitly-specified file doesn't exist", () => {
141-
files.create("package.json", { version: "4.5.6" });
142-
143-
let cli = bump("major LICENSE README.* *.js");
185+
files.create("package.json", { version: "1.2.3" });
144186

145-
expect(cli).to.have.stderr("");
146-
expect(cli).to.have.exitCode(0);
187+
let cli = bump("major README.md");
147188

148-
expect(cli).to.have.stdout(
149-
`${check} Updated package.json to 5.0.0\n`
150-
);
189+
expect(cli).to.have.stderr("Could not find file: README.md.\n");
190+
expect(cli).to.have.exitCode(1);
151191

152-
expect(files.json("package.json").version).to.equal("5.0.0");
153-
expect(files.text("LICENSE")).to.match(/MyApp v1.2.3 Copyright/);
154-
expect(files.text("README.md")).to.match(/version 5.6.7 and v8.9.10 should not be changed/);
155-
expect(files.text("README.md")).to.match(/version 1.2.3 and v1.2.3 should both get updated/);
156-
expect(files.text("script1.js")).to.match(/make sure v1.2.3 gets replaced correctly/);
157-
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
158-
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
159-
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
192+
expect(files.json("package.json")).to.deep.equal({ version: "1.2.3" });
160193
});
161194

162195
it("should error if a glob pattern doesn't match any files", () => {
163-
files.create("package.json", { version: "4.5.6" });
196+
files.create("package.json", { version: "1.2.3" });
164197

165-
let cli = bump("major README.* *.js");
198+
let cli = bump("major **/*.js");
166199

167-
expect(cli).to.have.stderr("");
168-
expect(cli).to.have.exitCode(0);
200+
expect(cli).to.have.stderr('Could not find any files matching "**/*.js".\n');
201+
expect(cli).to.have.exitCode(1);
169202

170-
expect(cli).to.have.stdout(
171-
`${check} Updated package.json to 5.0.0\n`
172-
);
173-
174-
expect(files.json("package.json").version).to.equal("5.0.0");
175-
expect(files.text("LICENSE")).to.match(/MyApp v1.2.3 Copyright/);
176-
expect(files.text("README.md")).to.match(/version 5.6.7 and v8.9.10 should not be changed/);
177-
expect(files.text("README.md")).to.match(/version 1.2.3 and v1.2.3 should both get updated/);
178-
expect(files.text("script1.js")).to.match(/make sure v1.2.3 gets replaced correctly/);
179-
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
180-
expect(files.text("script1.js")).to.match(/let version = "1.2.3";/);
181-
expect(files.text("script2.js")).to.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
203+
expect(files.json("package.json")).to.deep.equal({ version: "1.2.3" });
182204
});
183205

184206
});

0 commit comments

Comments
 (0)