|
3 | 3 | const { check, files, bump } = require("../utils"); |
4 | 4 | const { expect } = require("chai"); |
5 | 5 |
|
6 | | -describe.skip("bump [release]", () => { |
| 6 | +describe("bump [version]", () => { |
7 | 7 |
|
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" }); |
10 | 10 |
|
11 | | - let cli = bump("major"); |
| 11 | + let cli = bump("123.45.678"); |
12 | 12 |
|
13 | 13 | expect(cli).to.have.stderr(""); |
14 | 14 | expect(cli).to.have.exitCode(0); |
15 | 15 |
|
16 | 16 | 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` |
18 | 18 | ); |
19 | 19 |
|
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" }); |
21 | 21 | }); |
22 | 22 |
|
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" }); |
25 | 25 |
|
26 | | - let cli = bump("--major"); |
| 26 | + let cli = bump("0.0.0"); |
27 | 27 |
|
28 | 28 | expect(cli).to.have.stderr(""); |
29 | 29 | expect(cli).to.have.exitCode(0); |
30 | 30 |
|
31 | 31 | 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` |
33 | 33 | ); |
34 | 34 |
|
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" }); |
36 | 36 | }); |
37 | 37 |
|
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" }); |
40 | 40 |
|
41 | | - let cli = bump("--major"); |
| 41 | + let cli = bump("123.45.678-beta"); |
42 | 42 |
|
43 | 43 | expect(cli).to.have.stderr(""); |
44 | 44 | expect(cli).to.have.exitCode(0); |
45 | 45 |
|
46 | 46 | 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` |
48 | 48 | ); |
49 | 49 |
|
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" }); |
51 | 51 | }); |
52 | 52 |
|
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" }); |
55 | 55 |
|
56 | | - let cli = bump("--major --preid alpha"); |
| 56 | + let cli = bump("123.45.678-910"); |
57 | 57 |
|
58 | 58 | expect(cli).to.have.stderr(""); |
59 | 59 | expect(cli).to.have.exitCode(0); |
60 | 60 |
|
61 | 61 | 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` |
63 | 63 | ); |
64 | 64 |
|
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" }); |
66 | 66 | }); |
67 | 67 |
|
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" }); |
70 | 70 |
|
71 | | - let cli = bump("major"); |
| 71 | + let cli = bump("123.45.678-beta.910"); |
72 | 72 |
|
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"); |
75 | 102 |
|
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` |
78 | 108 | ); |
79 | 109 |
|
80 | | - expect(files.json("package.json")).to.deep.equal({}); |
| 110 | + expect(files.json("package.json")).to.deep.equal({ version: "123.45.678-alpha.beta" }); |
81 | 111 | }); |
82 | 112 |
|
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", () => { |
84 | 129 | files.create("package.json", { version: "" }); |
85 | 130 |
|
86 | | - let cli = bump("major", { env: { DEBUG: "true" }}); |
| 131 | + let cli = bump("1.2.3"); |
87 | 132 |
|
88 | 133 | 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"); |
90 | 136 |
|
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 | + }); |
94 | 139 |
|
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" }); |
96 | 150 | }); |
97 | 151 |
|
98 | 152 | }); |
0 commit comments