Skip to content

Commit da28fab

Browse files
Now using Chai-Exec for CLI testing
1 parent 73f8144 commit da28fab

15 files changed

+430
-494
lines changed

test/fixtures/cli.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

test/fixtures/setup-chai.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
3+
const chai = require("chai");
4+
const chaiExec = require("chai-exec");
5+
6+
chai.use(chaiExec);
7+
chai.should();
8+
9+
chaiExec.defaults = {
10+
command: "node",
11+
args: "../../bin/bump.js",
12+
options: {
13+
cwd: "test/.tmp",
14+
},
15+
};

test/specs/commit.spec.js

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
"use strict";
22

3-
const cli = require("../fixtures/cli");
43
const mocks = require("../fixtures/mocks");
54
const files = require("../fixtures/files");
65
const check = require("../fixtures/check");
7-
const chai = require("chai");
8-
9-
chai.should();
6+
const chaiExec = require("chai-exec");
107

118
describe("bump --commit", () => {
129

1310
it("should commit the manifest file to git", () => {
1411
files.create("package.json", { version: "1.0.0" });
1512

16-
let output = cli.exec("--major --commit");
13+
let bump = chaiExec("--major --commit");
1714

18-
output.stderr.should.be.empty;
19-
output.status.should.equal(0);
15+
bump.stderr.should.be.empty;
16+
bump.should.have.exitCode(0);
2017

21-
output.lines.should.deep.equal([
22-
`${check} Updated package.json to 2.0.0`,
23-
`${check} Git commit`,
24-
]);
18+
bump.should.have.stdout(
19+
`${check} Updated package.json to 2.0.0\n` +
20+
`${check} Git commit\n`
21+
);
2522

2623
let git = mocks.git();
2724
git.length.should.equal(1);
@@ -34,17 +31,17 @@ describe("bump --commit", () => {
3431
files.create("bower.json", { version: "1.0.0" });
3532
files.create("component.json", { version: "1.0.0" });
3633

37-
let output = cli.exec("--minor --commit");
34+
let bump = chaiExec("--minor --commit");
3835

39-
output.stderr.should.be.empty;
40-
output.status.should.equal(0);
36+
bump.stderr.should.be.empty;
37+
bump.should.have.exitCode(0);
4138

42-
output.lines.should.deep.equal([
43-
`${check} Updated package.json to 1.1.0`,
44-
`${check} Updated bower.json to 1.1.0`,
45-
`${check} Updated component.json to 1.1.0`,
46-
`${check} Git commit`,
47-
]);
39+
bump.should.have.stdout(
40+
`${check} Updated package.json to 1.1.0\n` +
41+
`${check} Updated bower.json to 1.1.0\n` +
42+
`${check} Updated component.json to 1.1.0\n` +
43+
`${check} Git commit\n`
44+
);
4845

4946
let git = mocks.git();
5047
git.length.should.equal(1);
@@ -55,15 +52,15 @@ describe("bump --commit", () => {
5552
it("should commit all files to git", () => {
5653
files.create("package.json", { version: "1.0.0" });
5754

58-
let output = cli.exec("--minor --commit --all");
55+
let bump = chaiExec("--minor --commit --all");
5956

60-
output.stderr.should.be.empty;
61-
output.status.should.equal(0);
57+
bump.stderr.should.be.empty;
58+
bump.should.have.exitCode(0);
6259

63-
output.lines.should.deep.equal([
64-
`${check} Updated package.json to 1.1.0`,
65-
`${check} Git commit`,
66-
]);
60+
bump.should.have.stdout(
61+
`${check} Updated package.json to 1.1.0\n` +
62+
`${check} Git commit\n`
63+
);
6764

6865
let git = mocks.git();
6966
git.length.should.equal(1);
@@ -74,15 +71,15 @@ describe("bump --commit", () => {
7471
it("should commit the manifest files to git with a message", () => {
7572
files.create("package.json", { version: "1.0.0" });
7673

77-
let output = cli.exec("--patch --all --commit my-message");
74+
let bump = chaiExec("--patch --all --commit my-message");
7875

79-
output.stderr.should.be.empty;
80-
output.status.should.equal(0);
76+
bump.stderr.should.be.empty;
77+
bump.should.have.exitCode(0);
8178

82-
output.lines.should.deep.equal([
83-
`${check} Updated package.json to 1.0.1`,
84-
`${check} Git commit`,
85-
]);
79+
bump.should.have.stdout(
80+
`${check} Updated package.json to 1.0.1\n` +
81+
`${check} Git commit\n`
82+
);
8683

8784
let git = mocks.git();
8885
git.length.should.equal(1);

test/specs/grep.spec.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
"use strict";
22

3-
const cli = require("../fixtures/cli");
43
const files = require("../fixtures/files");
54
const check = require("../fixtures/check");
6-
const chai = require("chai");
7-
8-
chai.should();
5+
const chaiExec = require("chai-exec");
96

107
describe("bump --grep", () => {
118

@@ -16,17 +13,17 @@ describe("bump --grep", () => {
1613
files.copy("script1.js");
1714
files.copy("script2.js");
1815

19-
let output = cli.exec("--major --grep LICENSE README.* *.js");
16+
let bump = chaiExec("--major --grep LICENSE README.* *.js");
2017

21-
output.stderr.should.be.empty;
22-
output.status.should.equal(0);
18+
bump.stderr.should.be.empty;
19+
bump.should.have.exitCode(0);
2320

24-
output.lines.should.deep.equal([
25-
`${check} Updated package.json to 2.0.0`,
26-
`${check} Updated README.md to 2.0.0`,
27-
`${check} Updated script1.js to 2.0.0`,
28-
`${check} Updated LICENSE to 2.0.0`,
29-
]);
21+
bump.should.have.stdout(
22+
`${check} Updated package.json to 2.0.0\n` +
23+
`${check} Updated README.md to 2.0.0\n` +
24+
`${check} Updated script1.js to 2.0.0\n` +
25+
`${check} Updated LICENSE to 2.0.0\n`
26+
);
3027

3128
files.json("package.json").version.should.equal("2.0.0");
3229
files.text("LICENSE").should.match(/MyApp v2.0.0 Copyright/);
@@ -43,17 +40,17 @@ describe("bump --grep", () => {
4340
files.copy("script1.js");
4441
files.copy("script2.js");
4542

46-
let output = cli.exec("--major --grep LICENSE README.* *.js");
43+
let bump = chaiExec("--major --grep LICENSE README.* *.js");
4744

48-
output.stderr.should.be.empty;
49-
output.status.should.equal(0);
45+
bump.stderr.should.be.empty;
46+
bump.should.have.exitCode(0);
5047

51-
output.lines.should.deep.equal([
52-
`${check} Updated package.json to 2.0.0`,
53-
`${check} Updated README.md to 2.0.0`,
54-
`${check} Updated script1.js to 2.0.0`,
55-
`${check} Updated LICENSE to 2.0.0`,
56-
]);
48+
bump.should.have.stdout(
49+
`${check} Updated package.json to 2.0.0\n` +
50+
`${check} Updated README.md to 2.0.0\n` +
51+
`${check} Updated script1.js to 2.0.0\n` +
52+
`${check} Updated LICENSE to 2.0.0\n`
53+
);
5754

5855
files.text("README.md").should.match(/version 5.6.7 and v8.9.10 should not be changed/);
5956
files.text("script2.js").should.match(/version 3.2.1 and v8.9.10 don't match the old version number/);
@@ -66,14 +63,14 @@ describe("bump --grep", () => {
6663
files.copy("script1.js");
6764
files.copy("script2.js");
6865

69-
let output = cli.exec("--major --grep LICENSE README.* *.js");
66+
let bump = chaiExec("--major --grep LICENSE README.* *.js");
7067

71-
output.stderr.should.be.empty;
72-
output.status.should.equal(0);
68+
bump.stderr.should.be.empty;
69+
bump.should.have.exitCode(0);
7370

74-
output.lines.should.deep.equal([
75-
`${check} Updated package.json to 5.0.0`,
76-
]);
71+
bump.should.have.stdout(
72+
`${check} Updated package.json to 5.0.0\n`
73+
);
7774

7875
files.json("package.json").version.should.equal("5.0.0");
7976
files.text("LICENSE").should.match(/MyApp v1.2.3 Copyright/);

test/specs/lock.spec.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
"use strict";
22

3-
const cli = require("../fixtures/cli");
43
const files = require("../fixtures/files");
54
const check = require("../fixtures/check");
6-
const chai = require("chai");
7-
8-
chai.should();
5+
const chaiExec = require("chai-exec");
96

107
describe("bump --lock", () => {
118
it("should not increment lock file by default", () => {
129
files.create("package-lock.json", { version: "1.0.0" });
1310

14-
let output = cli.exec("--patch");
11+
let bump = chaiExec("--patch");
1512

16-
output.stderr.should.be.empty;
17-
output.stdout.should.be.empty;
18-
output.status.should.equal(0);
13+
bump.stderr.should.be.empty;
14+
bump.stdout.should.be.empty;
15+
bump.should.have.exitCode(0);
1916

2017
files.json("package-lock.json").should.deep.equal({ version: "1.0.0" });
2118
});
2219

2320
it("should increment version when lock option is provided", () => {
2421
files.create("package-lock.json", { version: "0.0.0" });
2522

26-
let output = cli.exec("--patch --lock");
23+
let bump = chaiExec("--patch --lock");
2724

28-
output.stderr.should.be.empty;
29-
output.status.should.equal(0);
25+
bump.stderr.should.be.empty;
26+
bump.should.have.exitCode(0);
3027

31-
output.lines.should.deep.equal([
32-
`${check} Updated package-lock.json to 0.0.1`,
33-
]);
28+
bump.should.have.stdout(
29+
`${check} Updated package-lock.json to 0.0.1\n`
30+
);
3431

3532
files.json("package-lock.json").should.deep.equal({ version: "0.0.1" });
3633
});

0 commit comments

Comments
 (0)