Skip to content

Commit 5fd01a9

Browse files
Added tests for "bump #.#.#"
1 parent 5fe5e0a commit 5fd01a9

1 file changed

Lines changed: 90 additions & 36 deletions

File tree

test/specs/release.spec.js

Lines changed: 90 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,96 +3,150 @@
33
const { check, files, bump } = require("../utils");
44
const { expect } = require("chai");
55

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

8-
it("should increment an all-zero version number", () => {
9-
files.create("package.json", { version: "0.0.0" });
8+
it("should accept an #.#.# version number", () => {
9+
files.create("package.json", { version: "1.0.0" });
1010

11-
let cli = bump("major");
11+
let cli = bump("123.45.678");
1212

1313
expect(cli).to.have.stderr("");
1414
expect(cli).to.have.exitCode(0);
1515

1616
expect(cli).to.have.stdout(
17-
`${check} Updated package.json to 1.0.0\n`
17+
`${check} Updated package.json to 123.45.678\n`
1818
);
1919

20-
expect(files.json("package.json")).to.deep.equal({ version: "1.0.0" });
20+
expect(files.json("package.json")).to.deep.equal({ version: "123.45.678" });
2121
});
2222

23-
it("should reset the minor and patch", () => {
24-
files.create("package.json", { version: "1.2.3" });
23+
it("should accept an #.#.# version number that's all zeroes", () => {
24+
files.create("package.json", { version: "1.0.0" });
2525

26-
let cli = bump("--major");
26+
let cli = bump("0.0.0");
2727

2828
expect(cli).to.have.stderr("");
2929
expect(cli).to.have.exitCode(0);
3030

3131
expect(cli).to.have.stdout(
32-
`${check} Updated package.json to 2.0.0\n`
32+
`${check} Updated package.json to 0.0.0\n`
3333
);
3434

35-
expect(files.json("package.json")).to.deep.equal({ version: "2.0.0" });
35+
expect(files.json("package.json")).to.deep.equal({ version: "0.0.0" });
3636
});
3737

38-
it("should reset the prerelease version", () => {
39-
files.create("package.json", { version: "1.2.3-beta.4" });
38+
it("should accept an #.#.#-X version number", () => {
39+
files.create("package.json", { version: "1.0.0" });
4040

41-
let cli = bump("--major");
41+
let cli = bump("123.45.678-beta");
4242

4343
expect(cli).to.have.stderr("");
4444
expect(cli).to.have.exitCode(0);
4545

4646
expect(cli).to.have.stdout(
47-
`${check} Updated package.json to 2.0.0\n`
47+
`${check} Updated package.json to 123.45.678-beta\n`
4848
);
4949

50-
expect(files.json("package.json")).to.deep.equal({ version: "2.0.0" });
50+
expect(files.json("package.json")).to.deep.equal({ version: "123.45.678-beta" });
5151
});
5252

53-
it("should not be affected by the --preid flag", () => {
54-
files.create("package.json", { version: "1.2.3-beta.4" });
53+
it("should accept an #.#.#-# version number", () => {
54+
files.create("package.json", { version: "1.0.0" });
5555

56-
let cli = bump("--major --preid alpha");
56+
let cli = bump("123.45.678-910");
5757

5858
expect(cli).to.have.stderr("");
5959
expect(cli).to.have.exitCode(0);
6060

6161
expect(cli).to.have.stdout(
62-
`${check} Updated package.json to 2.0.0\n`
62+
`${check} Updated package.json to 123.45.678-910\n`
6363
);
6464

65-
expect(files.json("package.json")).to.deep.equal({ version: "2.0.0" });
65+
expect(files.json("package.json")).to.deep.equal({ version: "123.45.678-910" });
6666
});
6767

68-
it("should error if there's no current version number", () => {
69-
files.create("package.json", {});
68+
it("should accept an #.#.#-X.# version number", () => {
69+
files.create("package.json", { version: "1.0.0" });
7070

71-
let cli = bump("major");
71+
let cli = bump("123.45.678-beta.910");
7272

73-
expect(cli).to.have.stdout("");
74-
expect(cli).to.have.exitCode(2);
73+
expect(cli).to.have.stderr("");
74+
expect(cli).to.have.exitCode(0);
75+
76+
expect(cli).to.have.stdout(
77+
`${check} Updated package.json to 123.45.678-beta.910\n`
78+
);
79+
80+
expect(files.json("package.json")).to.deep.equal({ version: "123.45.678-beta.910" });
81+
});
82+
83+
it("should accept an #.#.#-#.# version number", () => {
84+
files.create("package.json", { version: "1.0.0" });
85+
86+
let cli = bump("123.45.678-987.654");
87+
88+
expect(cli).to.have.stderr("");
89+
expect(cli).to.have.exitCode(0);
90+
91+
expect(cli).to.have.stdout(
92+
`${check} Updated package.json to 123.45.678-987.654\n`
93+
);
94+
95+
expect(files.json("package.json")).to.deep.equal({ version: "123.45.678-987.654" });
96+
});
97+
98+
it("should accept an #.#.#-X.X version number", () => {
99+
files.create("package.json", { version: "1.0.0" });
100+
101+
let cli = bump("123.45.678-alpha.beta");
75102

76-
expect(cli).to.have.stderr(
77-
"Unable to determine the current version number. Checked package.json, package-lock.json.\n"
103+
expect(cli).to.have.stderr("");
104+
expect(cli).to.have.exitCode(0);
105+
106+
expect(cli).to.have.stdout(
107+
`${check} Updated package.json to 123.45.678-alpha.beta\n`
78108
);
79109

80-
expect(files.json("package.json")).to.deep.equal({});
110+
expect(files.json("package.json")).to.deep.equal({ version: "123.45.678-alpha.beta" });
81111
});
82112

83-
it("should print a more detailed error if DEBUG is set", () => {
113+
it("should not be affected by the --preid flag", () => {
114+
files.create("package.json", { version: "1.0.0" });
115+
116+
let cli = bump("1.2.3-beta.1 --preid alpha");
117+
118+
expect(cli).to.have.stderr("");
119+
expect(cli).to.have.exitCode(0);
120+
121+
expect(cli).to.have.stdout(
122+
`${check} Updated package.json to 1.2.3-beta.1\n`
123+
);
124+
125+
expect(files.json("package.json")).to.deep.equal({ version: "1.2.3-beta.1" });
126+
});
127+
128+
it("should error if there's no current version number", () => {
84129
files.create("package.json", { version: "" });
85130

86-
let cli = bump("major", { env: { DEBUG: "true" }});
131+
let cli = bump("1.2.3");
87132

88133
expect(cli).to.have.stdout("");
89-
expect(cli).to.have.exitCode(2);
134+
expect(cli).to.have.exitCode(1);
135+
expect(cli).to.have.stderr("Unable to determine the current version number. Checked package.json.\n");
90136

91-
expect(cli).to.have.stderr.that.matches(
92-
/^Error: Unable to determine the current version number. Checked package.json, package-lock.json.\n\s+at \w+/
93-
);
137+
expect(files.json("package.json")).to.deep.equal({ version: "" });
138+
});
94139

95-
expect(files.json("package.json")).to.deep.equal({});
140+
it("should error on an X.X.X version number", () => {
141+
files.create("package.json", { version: "1.0.0" });
142+
143+
let cli = bump("A.B.C");
144+
145+
expect(cli).to.have.stdout("");
146+
expect(cli).to.have.stderr("Could not find file: A.B.C.\n");
147+
expect(cli).to.have.exitCode(1);
148+
149+
expect(files.json("package.json")).to.deep.equal({ version: "1.0.0" });
96150
});
97151

98152
});

0 commit comments

Comments
 (0)