1 | 'use strict';
|
2 |
|
3 | var _path = require('path');
|
4 |
|
5 | var _path2 = _interopRequireDefault(_path);
|
6 |
|
7 | var _test = require('@commitlint/test');
|
8 |
|
9 | var _ava = require('ava');
|
10 |
|
11 | var _ava2 = _interopRequireDefault(_ava);
|
12 |
|
13 | var _execa = require('execa');
|
14 |
|
15 | var _execa2 = _interopRequireDefault(_execa);
|
16 |
|
17 | var _lodash = require('lodash');
|
18 |
|
19 | var _sander = require('sander');
|
20 |
|
21 | var sander = _interopRequireWildcard(_sander);
|
22 |
|
23 | var _stringToStream = require('string-to-stream');
|
24 |
|
25 | var _stringToStream2 = _interopRequireDefault(_stringToStream);
|
26 |
|
27 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
28 |
|
29 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
30 |
|
31 | const bin = _path2.default.join(__dirname, './cli.js');
|
32 |
|
33 | const cli = (args, options) => (input = '') => {
|
34 | const c = (0, _execa2.default)(bin, args, {
|
35 | capture: ['stdout'],
|
36 | cwd: options.cwd,
|
37 | env: options.env
|
38 | });
|
39 | (0, _stringToStream2.default)(input).pipe(c.stdin);
|
40 | return c.catch(err => err);
|
41 | };
|
42 |
|
43 | (0, _ava2.default)('should throw when called without [input]', t => new Promise(function ($return, $error) {
|
44 | var cwd, actual;
|
45 | return Promise.resolve(_test.git.bootstrap('fixtures/default')).then(function ($await_1) {
|
46 | try {
|
47 | cwd = $await_1;
|
48 | return Promise.resolve(cli([], { cwd })()).then(function ($await_2) {
|
49 | try {
|
50 | actual = $await_2;
|
51 |
|
52 | t.is(actual.code, 1);
|
53 | return $return();
|
54 | } catch ($boundEx) {
|
55 | return $error($boundEx);
|
56 | }
|
57 | }.bind(this), $error);
|
58 | } catch ($boundEx) {
|
59 | return $error($boundEx);
|
60 | }
|
61 | }.bind(this), $error);
|
62 | }.bind(this)));
|
63 |
|
64 | (0, _ava2.default)('should reprint input from stdin', t => new Promise(function ($return, $error) {
|
65 | var cwd, actual;
|
66 | return Promise.resolve(_test.git.bootstrap('fixtures/default')).then(function ($await_3) {
|
67 | try {
|
68 | cwd = $await_3;
|
69 | return Promise.resolve(cli([], { cwd })('foo: bar')).then(function ($await_4) {
|
70 | try {
|
71 | actual = $await_4;
|
72 |
|
73 | t.true(actual.stdout.includes('foo: bar'));
|
74 | return $return();
|
75 | } catch ($boundEx) {
|
76 | return $error($boundEx);
|
77 | }
|
78 | }.bind(this), $error);
|
79 | } catch ($boundEx) {
|
80 | return $error($boundEx);
|
81 | }
|
82 | }.bind(this), $error);
|
83 | }.bind(this)));
|
84 |
|
85 | (0, _ava2.default)('should produce no success output with --quiet flag', t => new Promise(function ($return, $error) {
|
86 | var cwd, actual;
|
87 | return Promise.resolve(_test.git.bootstrap('fixtures/default')).then(function ($await_5) {
|
88 | try {
|
89 | cwd = $await_5;
|
90 | return Promise.resolve(cli(['--quiet'], { cwd })('foo: bar')).then(function ($await_6) {
|
91 | try {
|
92 | actual = $await_6;
|
93 |
|
94 | t.is(actual.stdout, '');
|
95 | t.is(actual.stderr, '');
|
96 | return $return();
|
97 | } catch ($boundEx) {
|
98 | return $error($boundEx);
|
99 | }
|
100 | }.bind(this), $error);
|
101 | } catch ($boundEx) {
|
102 | return $error($boundEx);
|
103 | }
|
104 | }.bind(this), $error);
|
105 | }.bind(this)));
|
106 |
|
107 | (0, _ava2.default)('should produce no success output with -q flag', t => new Promise(function ($return, $error) {
|
108 | var cwd, actual;
|
109 | return Promise.resolve(_test.git.bootstrap('fixtures/default')).then(function ($await_7) {
|
110 | try {
|
111 | cwd = $await_7;
|
112 | return Promise.resolve(cli(['-q'], { cwd })('foo: bar')).then(function ($await_8) {
|
113 | try {
|
114 | actual = $await_8;
|
115 |
|
116 | t.is(actual.stdout, '');
|
117 | t.is(actual.stderr, '');
|
118 | return $return();
|
119 | } catch ($boundEx) {
|
120 | return $error($boundEx);
|
121 | }
|
122 | }.bind(this), $error);
|
123 | } catch ($boundEx) {
|
124 | return $error($boundEx);
|
125 | }
|
126 | }.bind(this), $error);
|
127 | }.bind(this)));
|
128 |
|
129 | (0, _ava2.default)('should fail for input from stdin without rules', t => new Promise(function ($return, $error) {
|
130 | var cwd, actual;
|
131 | return Promise.resolve(_test.git.bootstrap('fixtures/empty')).then(function ($await_9) {
|
132 | try {
|
133 | cwd = $await_9;
|
134 | return Promise.resolve(cli([], { cwd })('foo: bar')).then(function ($await_10) {
|
135 | try {
|
136 | actual = $await_10;
|
137 |
|
138 | t.is(actual.code, 1);
|
139 | return $return();
|
140 | } catch ($boundEx) {
|
141 | return $error($boundEx);
|
142 | }
|
143 | }.bind(this), $error);
|
144 | } catch ($boundEx) {
|
145 | return $error($boundEx);
|
146 | }
|
147 | }.bind(this), $error);
|
148 | }.bind(this)));
|
149 |
|
150 | (0, _ava2.default)('should succeed for input from stdin with rules', t => new Promise(function ($return, $error) {
|
151 | var cwd, actual;
|
152 | return Promise.resolve(_test.git.bootstrap('fixtures/default')).then(function ($await_11) {
|
153 | try {
|
154 | cwd = $await_11;
|
155 | return Promise.resolve(cli([], { cwd })('type: bar')).then(function ($await_12) {
|
156 | try {
|
157 | actual = $await_12;
|
158 |
|
159 | t.is(actual.code, 0);
|
160 | return $return();
|
161 | } catch ($boundEx) {
|
162 | return $error($boundEx);
|
163 | }
|
164 | }.bind(this), $error);
|
165 | } catch ($boundEx) {
|
166 | return $error($boundEx);
|
167 | }
|
168 | }.bind(this), $error);
|
169 | }.bind(this)));
|
170 |
|
171 | (0, _ava2.default)('should fail for input from stdin with rule from rc', t => new Promise(function ($return, $error) {
|
172 | var cwd, actual;
|
173 | return Promise.resolve(_test.git.bootstrap('fixtures/simple')).then(function ($await_13) {
|
174 | try {
|
175 | cwd = $await_13;
|
176 | return Promise.resolve(cli([], { cwd })('foo: bar')).then(function ($await_14) {
|
177 | try {
|
178 | actual = $await_14;
|
179 |
|
180 | t.true(actual.stdout.includes('type must not be one of [foo]'));
|
181 | t.is(actual.code, 1);
|
182 | return $return();
|
183 | } catch ($boundEx) {
|
184 | return $error($boundEx);
|
185 | }
|
186 | }.bind(this), $error);
|
187 | } catch ($boundEx) {
|
188 | return $error($boundEx);
|
189 | }
|
190 | }.bind(this), $error);
|
191 | }.bind(this)));
|
192 |
|
193 | (0, _ava2.default)('should work with --config option', t => new Promise(function ($return, $error) {
|
194 | var file, cwd, actual;
|
195 | file = 'config/commitlint.config.js';
|
196 | return Promise.resolve(_test.git.bootstrap('fixtures/specify-config-file')).then(function ($await_15) {
|
197 | try {
|
198 | cwd = $await_15;
|
199 | return Promise.resolve(cli(['--config', file], { cwd })('foo: bar')).then(function ($await_16) {
|
200 | try {
|
201 | actual = $await_16;
|
202 |
|
203 | t.true(actual.stdout.includes('type must not be one of [foo]'));
|
204 | t.is(actual.code, 1);
|
205 | return $return();
|
206 | } catch ($boundEx) {
|
207 | return $error($boundEx);
|
208 | }
|
209 | }.bind(this), $error);
|
210 | } catch ($boundEx) {
|
211 | return $error($boundEx);
|
212 | }
|
213 | }.bind(this), $error);
|
214 | }.bind(this)));
|
215 |
|
216 | (0, _ava2.default)('should fail for input from stdin with rule from js', t => new Promise(function ($return, $error) {
|
217 | var cwd, actual;
|
218 | return Promise.resolve(_test.git.bootstrap('fixtures/extends-root')).then(function ($await_17) {
|
219 | try {
|
220 | cwd = $await_17;
|
221 | return Promise.resolve(cli(['--extends', './extended'], { cwd })('foo: bar')).then(function ($await_18) {
|
222 | try {
|
223 | actual = $await_18;
|
224 |
|
225 | t.true(actual.stdout.includes('type must not be one of [foo]'));
|
226 | t.is(actual.code, 1);
|
227 | return $return();
|
228 | } catch ($boundEx) {
|
229 | return $error($boundEx);
|
230 | }
|
231 | }.bind(this), $error);
|
232 | } catch ($boundEx) {
|
233 | return $error($boundEx);
|
234 | }
|
235 | }.bind(this), $error);
|
236 | }.bind(this)));
|
237 |
|
238 | (0, _ava2.default)('should produce no error output with --quiet flag', t => new Promise(function ($return, $error) {
|
239 | var cwd, actual;
|
240 | return Promise.resolve(_test.git.bootstrap('fixtures/simple')).then(function ($await_19) {
|
241 | try {
|
242 | cwd = $await_19;
|
243 | return Promise.resolve(cli(['--quiet'], { cwd })('foo: bar')).then(function ($await_20) {
|
244 | try {
|
245 | actual = $await_20;
|
246 |
|
247 | t.is(actual.stdout, '');
|
248 | t.is(actual.stderr, '');
|
249 | t.is(actual.code, 1);
|
250 | return $return();
|
251 | } catch ($boundEx) {
|
252 | return $error($boundEx);
|
253 | }
|
254 | }.bind(this), $error);
|
255 | } catch ($boundEx) {
|
256 | return $error($boundEx);
|
257 | }
|
258 | }.bind(this), $error);
|
259 | }.bind(this)));
|
260 |
|
261 | (0, _ava2.default)('should produce no error output with -q flag', t => new Promise(function ($return, $error) {
|
262 | var cwd, actual;
|
263 | return Promise.resolve(_test.git.bootstrap('fixtures/simple')).then(function ($await_21) {
|
264 | try {
|
265 | cwd = $await_21;
|
266 | return Promise.resolve(cli(['-q'], { cwd })('foo: bar')).then(function ($await_22) {
|
267 | try {
|
268 | actual = $await_22;
|
269 |
|
270 | t.is(actual.stdout, '');
|
271 | t.is(actual.stderr, '');
|
272 | t.is(actual.code, 1);
|
273 | return $return();
|
274 | } catch ($boundEx) {
|
275 | return $error($boundEx);
|
276 | }
|
277 | }.bind(this), $error);
|
278 | } catch ($boundEx) {
|
279 | return $error($boundEx);
|
280 | }
|
281 | }.bind(this), $error);
|
282 | }.bind(this)));
|
283 |
|
284 | (0, _ava2.default)('should work with husky commitmsg hook and git commit', () => new Promise(function ($return, $error) {
|
285 | var cwd;
|
286 | return Promise.resolve(_test.git.bootstrap('fixtures/husky/integration')).then(function ($await_23) {
|
287 | try {
|
288 | cwd = $await_23;
|
289 | return Promise.resolve(writePkg({ scripts: { commitmsg: `'${bin}' -e` } }, { cwd })).then(function ($await_24) {
|
290 | try {
|
291 | return Promise.resolve((0, _execa2.default)('npm', ['install'], { cwd })).then(function ($await_25) {
|
292 | try {
|
293 | return Promise.resolve((0, _execa2.default)('git', ['add', 'package.json'], { cwd })).then(function ($await_26) {
|
294 | try {
|
295 | return Promise.resolve((0, _execa2.default)('git', ['commit', '-m', '"test: this should work"'], { cwd })).then(function ($await_27) {
|
296 | try {
|
297 | return $return();
|
298 | } catch ($boundEx) {
|
299 | return $error($boundEx);
|
300 | }
|
301 | }.bind(this), $error);
|
302 | } catch ($boundEx) {
|
303 | return $error($boundEx);
|
304 | }
|
305 | }.bind(this), $error);
|
306 | } catch ($boundEx) {
|
307 | return $error($boundEx);
|
308 | }
|
309 | }.bind(this), $error);
|
310 | } catch ($boundEx) {
|
311 | return $error($boundEx);
|
312 | }
|
313 | }.bind(this), $error);
|
314 | } catch ($boundEx) {
|
315 | return $error($boundEx);
|
316 | }
|
317 | }.bind(this), $error);
|
318 | }.bind(this)));
|
319 |
|
320 | (0, _ava2.default)('should work with husky commitmsg hook in sub packages', () => new Promise(function ($return, $error) {
|
321 | var upper, cwd;
|
322 | return Promise.resolve(_test.git.bootstrap('fixtures/husky')).then(function ($await_28) {
|
323 | try {
|
324 | upper = $await_28;
|
325 | cwd = _path2.default.join(upper, 'integration');
|
326 | return Promise.resolve(writePkg({ scripts: { commitmsg: `'${bin}' -e` } }, { cwd: upper })).then(function ($await_29) {
|
327 | try {
|
328 | return Promise.resolve((0, _execa2.default)('npm', ['install'], { cwd })).then(function ($await_30) {
|
329 | try {
|
330 | return Promise.resolve((0, _execa2.default)('git', ['add', 'package.json'], { cwd })).then(function ($await_31) {
|
331 | try {
|
332 | return Promise.resolve((0, _execa2.default)('git', ['commit', '-m', '"test: this should work"'], { cwd })).then(function ($await_32) {
|
333 | try {
|
334 | return $return();
|
335 | } catch ($boundEx) {
|
336 | return $error($boundEx);
|
337 | }
|
338 | }.bind(this), $error);
|
339 | } catch ($boundEx) {
|
340 | return $error($boundEx);
|
341 | }
|
342 | }.bind(this), $error);
|
343 | } catch ($boundEx) {
|
344 | return $error($boundEx);
|
345 | }
|
346 | }.bind(this), $error);
|
347 | } catch ($boundEx) {
|
348 | return $error($boundEx);
|
349 | }
|
350 | }.bind(this), $error);
|
351 | } catch ($boundEx) {
|
352 | return $error($boundEx);
|
353 | }
|
354 | }.bind(this), $error);
|
355 | }.bind(this)));
|
356 |
|
357 | (0, _ava2.default)('should work with husky via commitlint -e $GIT_PARAMS', () => new Promise(function ($return, $error) {
|
358 | var cwd;
|
359 | return Promise.resolve(_test.git.bootstrap('fixtures/husky/integration')).then(function ($await_33) {
|
360 | try {
|
361 | cwd = $await_33;
|
362 | return Promise.resolve(writePkg({ scripts: { commitmsg: `'${bin}' -e $GIT_PARAMS` } }, { cwd })).then(function ($await_34) {
|
363 | try {
|
364 | return Promise.resolve((0, _execa2.default)('npm', ['install'], { cwd })).then(function ($await_35) {
|
365 | try {
|
366 | return Promise.resolve((0, _execa2.default)('git', ['add', 'package.json'], { cwd })).then(function ($await_36) {
|
367 | try {
|
368 | return Promise.resolve((0, _execa2.default)('git', ['commit', '-m', '"test: this should work"'], { cwd })).then(function ($await_37) {
|
369 | try {
|
370 | return $return();
|
371 | } catch ($boundEx) {
|
372 | return $error($boundEx);
|
373 | }
|
374 | }.bind(this), $error);
|
375 | } catch ($boundEx) {
|
376 | return $error($boundEx);
|
377 | }
|
378 | }.bind(this), $error);
|
379 | } catch ($boundEx) {
|
380 | return $error($boundEx);
|
381 | }
|
382 | }.bind(this), $error);
|
383 | } catch ($boundEx) {
|
384 | return $error($boundEx);
|
385 | }
|
386 | }.bind(this), $error);
|
387 | } catch ($boundEx) {
|
388 | return $error($boundEx);
|
389 | }
|
390 | }.bind(this), $error);
|
391 | }.bind(this)));
|
392 |
|
393 | (0, _ava2.default)('should work with husky via commitlint -e %GIT_PARAMS%', () => new Promise(function ($return, $error) {
|
394 | var cwd;
|
395 | return Promise.resolve(_test.git.bootstrap('fixtures/husky/integration')).then(function ($await_38) {
|
396 | try {
|
397 | cwd = $await_38;
|
398 | return Promise.resolve(writePkg({ scripts: { commitmsg: `'${bin}' -e %GIT_PARAMS%` } }, { cwd })).then(function ($await_39) {
|
399 | try {
|
400 | return Promise.resolve((0, _execa2.default)('npm', ['install'], { cwd })).then(function ($await_40) {
|
401 | try {
|
402 | return Promise.resolve((0, _execa2.default)('git', ['add', 'package.json'], { cwd })).then(function ($await_41) {
|
403 | try {
|
404 | return Promise.resolve((0, _execa2.default)('git', ['commit', '-m', '"test: this should work"'], { cwd })).then(function ($await_42) {
|
405 | try {
|
406 | return $return();
|
407 | } catch ($boundEx) {
|
408 | return $error($boundEx);
|
409 | }
|
410 | }.bind(this), $error);
|
411 | } catch ($boundEx) {
|
412 | return $error($boundEx);
|
413 | }
|
414 | }.bind(this), $error);
|
415 | } catch ($boundEx) {
|
416 | return $error($boundEx);
|
417 | }
|
418 | }.bind(this), $error);
|
419 | } catch ($boundEx) {
|
420 | return $error($boundEx);
|
421 | }
|
422 | }.bind(this), $error);
|
423 | } catch ($boundEx) {
|
424 | return $error($boundEx);
|
425 | }
|
426 | }.bind(this), $error);
|
427 | }.bind(this)));
|
428 |
|
429 | (0, _ava2.default)('should work with husky via commitlint -e $HUSKY_GIT_PARAMS', () => new Promise(function ($return, $error) {
|
430 | var cwd;
|
431 | return Promise.resolve(_test.git.bootstrap('fixtures/husky/integration')).then(function ($await_43) {
|
432 | try {
|
433 | cwd = $await_43;
|
434 | return Promise.resolve(writePkg({ scripts: { commitmsg: `'${bin}' -e $HUSKY_GIT_PARAMS` } }, { cwd })).then(function ($await_44) {
|
435 | try {
|
436 | return Promise.resolve((0, _execa2.default)('npm', ['install'], { cwd })).then(function ($await_45) {
|
437 | try {
|
438 | return Promise.resolve((0, _execa2.default)('git', ['add', 'package.json'], { cwd })).then(function ($await_46) {
|
439 | try {
|
440 | return Promise.resolve((0, _execa2.default)('git', ['commit', '-m', '"test: this should work"'], { cwd })).then(function ($await_47) {
|
441 | try {
|
442 | return $return();
|
443 | } catch ($boundEx) {
|
444 | return $error($boundEx);
|
445 | }
|
446 | }.bind(this), $error);
|
447 | } catch ($boundEx) {
|
448 | return $error($boundEx);
|
449 | }
|
450 | }.bind(this), $error);
|
451 | } catch ($boundEx) {
|
452 | return $error($boundEx);
|
453 | }
|
454 | }.bind(this), $error);
|
455 | } catch ($boundEx) {
|
456 | return $error($boundEx);
|
457 | }
|
458 | }.bind(this), $error);
|
459 | } catch ($boundEx) {
|
460 | return $error($boundEx);
|
461 | }
|
462 | }.bind(this), $error);
|
463 | }.bind(this)));
|
464 |
|
465 | (0, _ava2.default)('should work with husky via commitlint -e %HUSKY_GIT_PARAMS%', () => new Promise(function ($return, $error) {
|
466 | var cwd;
|
467 | return Promise.resolve(_test.git.bootstrap('fixtures/husky/integration')).then(function ($await_48) {
|
468 | try {
|
469 | cwd = $await_48;
|
470 | return Promise.resolve(writePkg({ scripts: { commitmsg: `'${bin}' -e %HUSKY_GIT_PARAMS%` } }, { cwd })).then(function ($await_49) {
|
471 | try {
|
472 | return Promise.resolve((0, _execa2.default)('npm', ['install'], { cwd })).then(function ($await_50) {
|
473 | try {
|
474 | return Promise.resolve((0, _execa2.default)('git', ['add', 'package.json'], { cwd })).then(function ($await_51) {
|
475 | try {
|
476 | return Promise.resolve((0, _execa2.default)('git', ['commit', '-m', '"test: this should work"'], { cwd })).then(function ($await_52) {
|
477 | try {
|
478 | return $return();
|
479 | } catch ($boundEx) {
|
480 | return $error($boundEx);
|
481 | }
|
482 | }.bind(this), $error);
|
483 | } catch ($boundEx) {
|
484 | return $error($boundEx);
|
485 | }
|
486 | }.bind(this), $error);
|
487 | } catch ($boundEx) {
|
488 | return $error($boundEx);
|
489 | }
|
490 | }.bind(this), $error);
|
491 | } catch ($boundEx) {
|
492 | return $error($boundEx);
|
493 | }
|
494 | }.bind(this), $error);
|
495 | } catch ($boundEx) {
|
496 | return $error($boundEx);
|
497 | }
|
498 | }.bind(this), $error);
|
499 | }.bind(this)));
|
500 |
|
501 | (0, _ava2.default)('should allow reading of environment variables for edit file, succeeding if valid', t => new Promise(function ($return, $error) {
|
502 | var cwd, actual;
|
503 | return Promise.resolve(_test.git.bootstrap('fixtures/simple')).then(function ($await_53) {
|
504 | try {
|
505 | cwd = $await_53;
|
506 | return Promise.resolve(sander.writeFile(cwd, 'commit-msg-file', 'foo')).then(function ($await_54) {
|
507 | try {
|
508 | return Promise.resolve(cli(['--env', 'variable'], {
|
509 | cwd,
|
510 | env: { variable: 'commit-msg-file' }
|
511 | })()).then(function ($await_55) {
|
512 | try {
|
513 | actual = $await_55;
|
514 |
|
515 | t.is(actual.code, 0);
|
516 | return $return();
|
517 | } catch ($boundEx) {
|
518 | return $error($boundEx);
|
519 | }
|
520 | }.bind(this), $error);
|
521 | } catch ($boundEx) {
|
522 | return $error($boundEx);
|
523 | }
|
524 | }.bind(this), $error);
|
525 | } catch ($boundEx) {
|
526 | return $error($boundEx);
|
527 | }
|
528 | }.bind(this), $error);
|
529 | }.bind(this)));
|
530 |
|
531 | (0, _ava2.default)('should allow reading of environment variables for edit file, failing if invalid', t => new Promise(function ($return, $error) {
|
532 | var cwd, actual;
|
533 | return Promise.resolve(_test.git.bootstrap('fixtures/simple')).then(function ($await_56) {
|
534 | try {
|
535 | cwd = $await_56;
|
536 | return Promise.resolve(sander.writeFile(cwd, 'commit-msg-file', 'foo: bar\n\nFoo bar bizz buzz.\n\nCloses #123.')).then(function ($await_57) {
|
537 | try {
|
538 | return Promise.resolve(cli(['--env', 'variable'], {
|
539 | cwd,
|
540 | env: { variable: 'commit-msg-file' }
|
541 | })()).then(function ($await_58) {
|
542 | try {
|
543 | actual = $await_58;
|
544 |
|
545 | t.is(actual.code, 1);
|
546 | return $return();
|
547 | } catch ($boundEx) {
|
548 | return $error($boundEx);
|
549 | }
|
550 | }.bind(this), $error);
|
551 | } catch ($boundEx) {
|
552 | return $error($boundEx);
|
553 | }
|
554 | }.bind(this), $error);
|
555 | } catch ($boundEx) {
|
556 | return $error($boundEx);
|
557 | }
|
558 | }.bind(this), $error);
|
559 | }.bind(this)));
|
560 |
|
561 | (0, _ava2.default)('should pick up parser preset and fail accordingly', t => new Promise(function ($return, $error) {
|
562 | var cwd, actual;
|
563 | return Promise.resolve(_test.git.bootstrap('fixtures/parser-preset')).then(function ($await_59) {
|
564 | try {
|
565 | cwd = $await_59;
|
566 | return Promise.resolve(cli(['--parser-preset', './parser-preset'], { cwd })('type(scope): subject')).then(function ($await_60) {
|
567 | try {
|
568 | actual = $await_60;
|
569 |
|
570 | t.is(actual.code, 1);
|
571 | t.true(actual.stdout.includes('may not be empty'));
|
572 | return $return();
|
573 | } catch ($boundEx) {
|
574 | return $error($boundEx);
|
575 | }
|
576 | }.bind(this), $error);
|
577 | } catch ($boundEx) {
|
578 | return $error($boundEx);
|
579 | }
|
580 | }.bind(this), $error);
|
581 | }.bind(this)));
|
582 |
|
583 | (0, _ava2.default)('should pick up parser preset and succeed accordingly', t => new Promise(function ($return, $error) {
|
584 | var cwd, actual;
|
585 | return Promise.resolve(_test.git.bootstrap('fixtures/parser-preset')).then(function ($await_61) {
|
586 | try {
|
587 | cwd = $await_61;
|
588 | return Promise.resolve(cli(['--parser-preset', './parser-preset'], { cwd })('----type(scope): subject')).then(function ($await_62) {
|
589 | try {
|
590 | actual = $await_62;
|
591 |
|
592 | t.is(actual.code, 0);
|
593 | return $return();
|
594 | } catch ($boundEx) {
|
595 | return $error($boundEx);
|
596 | }
|
597 | }.bind(this), $error);
|
598 | } catch ($boundEx) {
|
599 | return $error($boundEx);
|
600 | }
|
601 | }.bind(this), $error);
|
602 | }.bind(this)));
|
603 |
|
604 | (0, _ava2.default)('should pick up config from outside git repo and fail accordingly', t => new Promise(function ($return, $error) {
|
605 | var outer, cwd, actual;
|
606 | return Promise.resolve(_test.fix.bootstrap('fixtures/outer-scope')).then(function ($await_63) {
|
607 | try {
|
608 | outer = $await_63;
|
609 | return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_64) {
|
610 | try {
|
611 | cwd = $await_64;
|
612 | return Promise.resolve(cli([], { cwd })('inner: bar')).then(function ($await_65) {
|
613 | try {
|
614 | actual = $await_65;
|
615 |
|
616 | t.is(actual.code, 1);
|
617 | return $return();
|
618 | } catch ($boundEx) {
|
619 | return $error($boundEx);
|
620 | }
|
621 | }.bind(this), $error);
|
622 | } catch ($boundEx) {
|
623 | return $error($boundEx);
|
624 | }
|
625 | }.bind(this), $error);
|
626 | } catch ($boundEx) {
|
627 | return $error($boundEx);
|
628 | }
|
629 | }.bind(this), $error);
|
630 | }.bind(this)));
|
631 |
|
632 | (0, _ava2.default)('should pick up config from outside git repo and succeed accordingly', t => new Promise(function ($return, $error) {
|
633 | var outer, cwd, actual;
|
634 | return Promise.resolve(_test.fix.bootstrap('fixtures/outer-scope')).then(function ($await_66) {
|
635 | try {
|
636 | outer = $await_66;
|
637 | return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_67) {
|
638 | try {
|
639 | cwd = $await_67;
|
640 | return Promise.resolve(cli([], { cwd })('outer: bar')).then(function ($await_68) {
|
641 | try {
|
642 | actual = $await_68;
|
643 |
|
644 | t.is(actual.code, 0);
|
645 | return $return();
|
646 | } catch ($boundEx) {
|
647 | return $error($boundEx);
|
648 | }
|
649 | }.bind(this), $error);
|
650 | } catch ($boundEx) {
|
651 | return $error($boundEx);
|
652 | }
|
653 | }.bind(this), $error);
|
654 | } catch ($boundEx) {
|
655 | return $error($boundEx);
|
656 | }
|
657 | }.bind(this), $error);
|
658 | }.bind(this)));
|
659 |
|
660 | (0, _ava2.default)('should pick up config from inside git repo with precedence and succeed accordingly', t => new Promise(function ($return, $error) {
|
661 | var outer, cwd, actual;
|
662 | return Promise.resolve(_test.fix.bootstrap('fixtures/inner-scope')).then(function ($await_69) {
|
663 | try {
|
664 | outer = $await_69;
|
665 | return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_70) {
|
666 | try {
|
667 | cwd = $await_70;
|
668 | return Promise.resolve(cli([], { cwd })('inner: bar')).then(function ($await_71) {
|
669 | try {
|
670 | actual = $await_71;
|
671 |
|
672 | t.is(actual.code, 0);
|
673 | return $return();
|
674 | } catch ($boundEx) {
|
675 | return $error($boundEx);
|
676 | }
|
677 | }.bind(this), $error);
|
678 | } catch ($boundEx) {
|
679 | return $error($boundEx);
|
680 | }
|
681 | }.bind(this), $error);
|
682 | } catch ($boundEx) {
|
683 | return $error($boundEx);
|
684 | }
|
685 | }.bind(this), $error);
|
686 | }.bind(this)));
|
687 |
|
688 | (0, _ava2.default)('should pick up config from inside git repo with precedence and fail accordingly', t => new Promise(function ($return, $error) {
|
689 | var outer, cwd, actual;
|
690 | return Promise.resolve(_test.fix.bootstrap('fixtures/inner-scope')).then(function ($await_72) {
|
691 | try {
|
692 | outer = $await_72;
|
693 | return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_73) {
|
694 | try {
|
695 | cwd = $await_73;
|
696 | return Promise.resolve(cli([], { cwd })('outer: bar')).then(function ($await_74) {
|
697 | try {
|
698 | actual = $await_74;
|
699 |
|
700 | t.is(actual.code, 1);
|
701 | return $return();
|
702 | } catch ($boundEx) {
|
703 | return $error($boundEx);
|
704 | }
|
705 | }.bind(this), $error);
|
706 | } catch ($boundEx) {
|
707 | return $error($boundEx);
|
708 | }
|
709 | }.bind(this), $error);
|
710 | } catch ($boundEx) {
|
711 | return $error($boundEx);
|
712 | }
|
713 | }.bind(this), $error);
|
714 | }.bind(this)));
|
715 |
|
716 | (0, _ava2.default)('should handle --amend with signoff', () => new Promise(function ($return, $error) {
|
717 | var cwd;
|
718 | return Promise.resolve(_test.git.bootstrap('fixtures/signoff')).then(function ($await_75) {
|
719 | try {
|
720 | cwd = $await_75;
|
721 | return Promise.resolve(writePkg({ scripts: { commitmsg: `'${bin}' -e` } }, { cwd })).then(function ($await_76) {
|
722 | try {
|
723 | return Promise.resolve((0, _execa2.default)('npm', ['install'], { cwd })).then(function ($await_77) {
|
724 | try {
|
725 | return Promise.resolve((0, _execa2.default)('git', ['add', 'package.json'], { cwd })).then(function ($await_78) {
|
726 | try {
|
727 | return Promise.resolve((0, _execa2.default)('git', ['commit', '-m', '"test: this should work"', '--signoff'], { cwd })).then(function ($await_79) {
|
728 | try {
|
729 | return Promise.resolve((0, _execa2.default)('git', ['commit', '--amend', '--no-edit'], { cwd })).then(function ($await_80) {
|
730 | try {
|
731 | return $return();
|
732 | } catch ($boundEx) {
|
733 | return $error($boundEx);
|
734 | }
|
735 | }.bind(this), $error);
|
736 | } catch ($boundEx) {
|
737 | return $error($boundEx);
|
738 | }
|
739 | }.bind(this), $error);
|
740 | } catch ($boundEx) {
|
741 | return $error($boundEx);
|
742 | }
|
743 | }.bind(this), $error);
|
744 | } catch ($boundEx) {
|
745 | return $error($boundEx);
|
746 | }
|
747 | }.bind(this), $error);
|
748 | } catch ($boundEx) {
|
749 | return $error($boundEx);
|
750 | }
|
751 | }.bind(this), $error);
|
752 | } catch ($boundEx) {
|
753 | return $error($boundEx);
|
754 | }
|
755 | }.bind(this), $error);
|
756 | }.bind(this)));
|
757 |
|
758 | (0, _ava2.default)('should handle linting with issue prefixes', t => new Promise(function ($return, $error) {
|
759 | var cwd, actual;
|
760 | return Promise.resolve(_test.git.bootstrap('fixtures/issue-prefixes')).then(function ($await_81) {
|
761 | try {
|
762 | cwd = $await_81;
|
763 | return Promise.resolve(cli([], { cwd })('foobar REF-1')).then(function ($await_82) {
|
764 | try {
|
765 | actual = $await_82;
|
766 |
|
767 | t.is(actual.code, 0);
|
768 | return $return();
|
769 | } catch ($boundEx) {
|
770 | return $error($boundEx);
|
771 | }
|
772 | }.bind(this), $error);
|
773 | } catch ($boundEx) {
|
774 | return $error($boundEx);
|
775 | }
|
776 | }.bind(this), $error);
|
777 | }.bind(this)));
|
778 |
|
779 | (0, _ava2.default)('should print full commit message when input from stdin fails', t => new Promise(function ($return, $error) {
|
780 | var cwd, input, actual;
|
781 | return Promise.resolve(_test.git.bootstrap('fixtures/simple')).then(function ($await_83) {
|
782 | try {
|
783 | cwd = $await_83;
|
784 | input = 'foo: bar\n\nFoo bar bizz buzz.\n\nCloses #123.';
|
785 | return Promise.resolve(cli([], { cwd })(input)).then(function ($await_84) {
|
786 | try {
|
787 | actual = $await_84;
|
788 |
|
789 |
|
790 | t.true(actual.stdout.includes(input));
|
791 | t.is(actual.code, 1);
|
792 | return $return();
|
793 | } catch ($boundEx) {
|
794 | return $error($boundEx);
|
795 | }
|
796 | }.bind(this), $error);
|
797 | } catch ($boundEx) {
|
798 | return $error($boundEx);
|
799 | }
|
800 | }.bind(this), $error);
|
801 | }.bind(this)));
|
802 |
|
803 | (0, _ava2.default)('should not print full commit message when input succeeds', t => new Promise(function ($return, $error) {
|
804 | var cwd, message, actual;
|
805 | return Promise.resolve(_test.git.bootstrap('fixtures/default')).then(function ($await_85) {
|
806 | try {
|
807 | cwd = $await_85;
|
808 | message = 'type: bar\n\nFoo bar bizz buzz.\n\nCloses #123.';
|
809 | return Promise.resolve(cli([], { cwd })(message)).then(function ($await_86) {
|
810 | try {
|
811 | actual = $await_86;
|
812 |
|
813 |
|
814 | t.false(actual.stdout.includes(message));
|
815 | t.true(actual.stdout.includes(message.split('\n')[0]));
|
816 | t.is(actual.code, 0);
|
817 | return $return();
|
818 | } catch ($boundEx) {
|
819 | return $error($boundEx);
|
820 | }
|
821 | }.bind(this), $error);
|
822 | } catch ($boundEx) {
|
823 | return $error($boundEx);
|
824 | }
|
825 | }.bind(this), $error);
|
826 | }.bind(this)));
|
827 |
|
828 | (0, _ava2.default)('should fail for invalid formatters from configuration', t => new Promise(function ($return, $error) {
|
829 | var cwd, actual;
|
830 | return Promise.resolve(_test.git.bootstrap('fixtures/custom-formatter')).then(function ($await_87) {
|
831 | try {
|
832 | cwd = $await_87;
|
833 | return Promise.resolve(cli([], { cwd })('foo: bar')).then(function ($await_88) {
|
834 | try {
|
835 | actual = $await_88;
|
836 |
|
837 | t.true(actual.stderr.includes(`Using format custom-formatter, but cannot find the module`));
|
838 | t.is(actual.stdout, '');
|
839 | t.is(actual.code, 1);
|
840 | return $return();
|
841 | } catch ($boundEx) {
|
842 | return $error($boundEx);
|
843 | }
|
844 | }.bind(this), $error);
|
845 | } catch ($boundEx) {
|
846 | return $error($boundEx);
|
847 | }
|
848 | }.bind(this), $error);
|
849 | }.bind(this)));
|
850 |
|
851 | (0, _ava2.default)('should fail for invalid formatters from flags', t => new Promise(function ($return, $error) {
|
852 | var cwd, actual;
|
853 | return Promise.resolve(_test.git.bootstrap('fixtures/custom-formatter')).then(function ($await_89) {
|
854 | try {
|
855 | cwd = $await_89;
|
856 | return Promise.resolve(cli(['--format', 'through-flag'], { cwd })('foo: bar')).then(function ($await_90) {
|
857 | try {
|
858 | actual = $await_90;
|
859 |
|
860 | t.true(actual.stderr.includes(`Using format through-flag, but cannot find the module`));
|
861 | t.is(actual.stdout, '');
|
862 | t.is(actual.code, 1);
|
863 | return $return();
|
864 | } catch ($boundEx) {
|
865 | return $error($boundEx);
|
866 | }
|
867 | }.bind(this), $error);
|
868 | } catch ($boundEx) {
|
869 | return $error($boundEx);
|
870 | }
|
871 | }.bind(this), $error);
|
872 | }.bind(this)));
|
873 |
|
874 | (0, _ava2.default)('should work with absolute formatter path', t => new Promise(function ($return, $error) {
|
875 | var formatterPath, cwd, actual;
|
876 | formatterPath = _path2.default.resolve(__dirname, '../fixtures/custom-formatter/formatters/custom.js');
|
877 | return Promise.resolve(_test.git.bootstrap('fixtures/custom-formatter')).then(function ($await_91) {
|
878 | try {
|
879 | cwd = $await_91;
|
880 | return Promise.resolve(cli(['--format', formatterPath], { cwd })('test: this should work')).then(function ($await_92) {
|
881 | try {
|
882 | actual = $await_92;
|
883 |
|
884 |
|
885 | t.true(actual.stdout.includes('custom-formatter-ok'));
|
886 | t.is(actual.code, 0);
|
887 | return $return();
|
888 | } catch ($boundEx) {
|
889 | return $error($boundEx);
|
890 | }
|
891 | }.bind(this), $error);
|
892 | } catch ($boundEx) {
|
893 | return $error($boundEx);
|
894 | }
|
895 | }.bind(this), $error);
|
896 | }.bind(this)));
|
897 |
|
898 | (0, _ava2.default)('should work with relative formatter path', t => new Promise(function ($return, $error) {
|
899 | var cwd, actual;
|
900 | return Promise.resolve(_test.git.bootstrap('fixtures/custom-formatter')).then(function ($await_93) {
|
901 | try {
|
902 | cwd = _path2.default.resolve($await_93, './formatters');
|
903 | return Promise.resolve(cli(['--format', './custom.js'], { cwd })('test: this should work')).then(function ($await_94) {
|
904 | try {
|
905 | actual = $await_94;
|
906 |
|
907 |
|
908 | t.true(actual.stdout.includes('custom-formatter-ok'));
|
909 | t.is(actual.code, 0);
|
910 | return $return();
|
911 | } catch ($boundEx) {
|
912 | return $error($boundEx);
|
913 | }
|
914 | }.bind(this), $error);
|
915 | } catch ($boundEx) {
|
916 | return $error($boundEx);
|
917 | }
|
918 | }.bind(this), $error);
|
919 | }.bind(this)));
|
920 |
|
921 | function writePkg(payload, options) {
|
922 | return new Promise(function ($return, $error) {
|
923 | var pkgPath, pkg, result;
|
924 | pkgPath = _path2.default.join(options.cwd, 'package.json');
|
925 | return Promise.resolve(sander.readFile(pkgPath)).then(function ($await_95) {
|
926 | try {
|
927 | pkg = JSON.parse($await_95);
|
928 | result = (0, _lodash.merge)(pkg, payload);
|
929 | return Promise.resolve(sander.writeFile(pkgPath, JSON.stringify(result, null, ' '))).then(function ($await_96) {
|
930 | try {
|
931 | return $return();
|
932 | } catch ($boundEx) {
|
933 | return $error($boundEx);
|
934 | }
|
935 | }.bind(this), $error);
|
936 | } catch ($boundEx) {
|
937 | return $error($boundEx);
|
938 | }
|
939 | }.bind(this), $error);
|
940 | }.bind(this));
|
941 | }
|
942 |
|
\ | No newline at end of file |