Skip to content

Commit a872f61

Browse files
authored
Merge pull request #5 from commitizen/lu-inquirer
Depend directly on inquirer
2 parents d542cb5 + 40d200d commit a872f61

File tree

4 files changed

+48
-45
lines changed

4 files changed

+48
-45
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- '6'
4+
- '4'
5+
- '0.12'
6+
- '0.10'

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var inquirer = require('inquirer')
2+
13
// This can be any kind of SystemJS compatible module.
24
// We use Commonjs here, but ES6 or AMD would do just
35
// fine.
@@ -23,7 +25,7 @@ function prompter(cz, commit) {
2325
// See inquirer.js docs for specifics.
2426
// You can also opt to use another input
2527
// collection library if you prefer.
26-
cz.prompt([
28+
inquirer.prompt([
2729
{
2830
type: 'input',
2931
name: 'message',

index.test.js

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,62 @@
11
import sinon from 'sinon';
22
import chai from 'chai';
33
import sinonChai from 'sinon-chai';
4-
import {prompter} from './index';
4+
import proxyquire from 'proxyquire';
55

66
const {expect} = chai;
77
chai.use(sinonChai);
88

99
describe(`prompter`, () => {
10-
let cz, commit;
11-
beforeEach(() => {
12-
cz = {prompt: sinon.spy()};
10+
let inquirer, commit, prompter, commitAnswers;
11+
12+
before(() => {
1313
commit = sinon.spy();
14+
inquirer = {prompt: sinon.spy()};
15+
prompter = proxyquire('./', {inquirer}).prompter;
1416
});
1517

16-
it(`call cz.prompt`, () => {
17-
prompter(cz);
18-
expect(cz.prompt).to.have.been.calledWith(sinon.match.array, sinon.match.func);
18+
beforeEach(() => {
19+
prompter(null, commit);
20+
commitAnswers = inquirer.prompt.getCall(0).args[1];
1921
});
2022

21-
describe(`commitAnswers`, () => {
22-
let commitAnswers;
23-
beforeEach(() => {
24-
prompter(cz, commit);
25-
commitAnswers = cz.prompt.getCall(0).args[1];
26-
});
23+
it(`should call commit with the proper message`, () => {
24+
const message = 'sample commit message';
25+
const issues = 'CZ-234 CZ-235';
26+
const workflow = 'closed';
27+
const time = '3y 2w 7d 8h 30m';
28+
const comment = 'This took waaaaay too long';
29+
commitAnswers({message, issues, workflow, time, comment});
30+
expect(commit).to.have.been.calledWith([
31+
message,
32+
issues,
33+
`#${workflow}`,
34+
`#time ${time}`,
35+
`#comment ${comment}`
36+
].join(' '));
37+
});
2738

28-
it(`should call commit with the proper message`, () => {
39+
['workflow', 'time', 'comment'].forEach((item) => {
40+
it(`should just leave off ${item} if it's not specified`, () => {
2941
const message = 'sample commit message';
3042
const issues = 'CZ-234 CZ-235';
3143
const workflow = 'closed';
3244
const time = '3y 2w 7d 8h 30m';
3345
const comment = 'This took waaaaay too long';
34-
commitAnswers({message, issues, workflow, time, comment});
35-
expect(commit).to.have.been.calledWith([
46+
const answers = {message, issues, workflow, time, comment};
47+
delete answers[item];
48+
commitAnswers(answers);
49+
expect(commit).to.have.been.calledWith(filter([
3650
message,
3751
issues,
38-
`#${workflow}`,
39-
`#time ${time}`,
40-
`#comment ${comment}`
41-
].join(' '));
52+
item !== 'workflow' ? `#${workflow}` : undefined,
53+
item !== 'time' ? `#time ${time}` : undefined,
54+
item !== 'comment' ? `#comment ${comment}` : undefined
55+
]).join(' '));
4256
});
43-
44-
['workflow', 'time', 'comment'].forEach((item) => {
45-
it(`should just leave off ${item} if it's not specified`, () => {
46-
const message = 'sample commit message';
47-
const issues = 'CZ-234 CZ-235';
48-
const workflow = 'closed';
49-
const time = '3y 2w 7d 8h 30m';
50-
const comment = 'This took waaaaay too long';
51-
const answers = {message, issues, workflow, time, comment};
52-
delete answers[item];
53-
commitAnswers(answers);
54-
expect(commit).to.have.been.calledWith(filter([
55-
message,
56-
issues,
57-
item !== 'workflow' ? `#${workflow}` : undefined,
58-
item !== 'time' ? `#time ${time}` : undefined,
59-
item !== 'comment' ? `#comment ${comment}` : undefined
60-
]).join(' '));
61-
});
62-
})
6357
});
64-
6558
});
6659

6760
function filter(array) {
68-
return array.filter(function(item) {
69-
return !!item;
70-
});
61+
return array.filter(Boolean);
7162
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@
3434
"chai": "3.2.0",
3535
"mocha": "2.2.5",
3636
"nodemon": "1.4.0",
37+
"proxyquire": "^1.7.10",
3738
"sinon": "1.15.4",
3839
"sinon-chai": "2.8.0",
3940
"with-package": "0.2.0"
41+
},
42+
"dependencies": {
43+
"inquirer": "^1.1.3"
4044
}
4145
}

0 commit comments

Comments
 (0)