UNPKG

21.3 kBJavaScriptView Raw
1'use strict';
2
3var _path = require('path');
4
5var _path2 = _interopRequireDefault(_path);
6
7var _test = require('@commitlint/test');
8
9var _ava = require('ava');
10
11var _ava2 = _interopRequireDefault(_ava);
12
13var _resolveFrom = require('resolve-from');
14
15var _resolveFrom2 = _interopRequireDefault(_resolveFrom);
16
17var _ = require('.');
18
19var _2 = _interopRequireDefault(_);
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23const proxyquire = require('proxyquire').noCallThru().noPreserveCache();
24
25(0, _ava2.default)('extends-empty should have no rules', t => new Promise(function ($return, $error) {
26 var cwd, actual;
27 return Promise.resolve(_test.git.bootstrap('fixtures/extends-empty')).then(function ($await_1) {
28 try {
29 cwd = $await_1;
30 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_2) {
31 try {
32 actual = $await_2;
33
34 t.deepEqual(actual.rules, {});
35 return $return();
36 } catch ($boundEx) {
37 return $error($boundEx);
38 }
39 }.bind(this), $error);
40 } catch ($boundEx) {
41 return $error($boundEx);
42 }
43 }.bind(this), $error);
44}.bind(this)));
45
46(0, _ava2.default)('uses seed as configured', t => new Promise(function ($return, $error) {
47 var cwd, actual;
48 return Promise.resolve(_test.git.bootstrap('fixtures/extends-empty')).then(function ($await_3) {
49 try {
50 cwd = $await_3;
51 return Promise.resolve((0, _2.default)({ rules: { foo: 'bar' } }, { cwd })).then(function ($await_4) {
52 try {
53 actual = $await_4;
54
55 t.is(actual.rules.foo, 'bar');
56 return $return();
57 } catch ($boundEx) {
58 return $error($boundEx);
59 }
60 }.bind(this), $error);
61 } catch ($boundEx) {
62 return $error($boundEx);
63 }
64 }.bind(this), $error);
65}.bind(this)));
66
67(0, _ava2.default)('rules should be loaded from relative config file', t => new Promise(function ($return, $error) {
68 var file, cwd, actual;
69 file = 'config/commitlint.config.js';
70 return Promise.resolve(_test.git.bootstrap('fixtures/specify-config-file')).then(function ($await_5) {
71 try {
72 cwd = $await_5;
73 return Promise.resolve((0, _2.default)({}, { cwd, file })).then(function ($await_6) {
74 try {
75 actual = $await_6;
76
77 t.is(actual.rules.foo, 'bar');
78 return $return();
79 } catch ($boundEx) {
80 return $error($boundEx);
81 }
82 }.bind(this), $error);
83 } catch ($boundEx) {
84 return $error($boundEx);
85 }
86 }.bind(this), $error);
87}.bind(this)));
88
89(0, _ava2.default)('rules should be loaded from absolute config file', t => new Promise(function ($return, $error) {
90 var cwd, file, actual;
91 return Promise.resolve(_test.git.bootstrap('fixtures/specify-config-file')).then(function ($await_7) {
92 try {
93 cwd = $await_7;
94 file = _path2.default.join(cwd, 'config/commitlint.config.js');
95 return Promise.resolve((0, _2.default)({}, { cwd: process.cwd(), file })).then(function ($await_8) {
96 try {
97 actual = $await_8;
98
99 t.is(actual.rules.foo, 'bar');
100 return $return();
101 } catch ($boundEx) {
102 return $error($boundEx);
103 }
104 }.bind(this), $error);
105 } catch ($boundEx) {
106 return $error($boundEx);
107 }
108 }.bind(this), $error);
109}.bind(this)));
110
111(0, _ava2.default)('plugins should be loaded from seed', t => new Promise(function ($return, $error) {
112 var plugin, scopedPlugin, stubbedLoad, cwd, actual;
113 plugin = { '@global': true };
114 scopedPlugin = { '@global': true };
115 stubbedLoad = proxyquire('.', {
116 'commitlint-plugin-example': plugin,
117 '@scope/commitlint-plugin-example': scopedPlugin
118 });
119 return Promise.resolve(_test.git.bootstrap('fixtures/extends-empty')).then(function ($await_9) {
120 try {
121 cwd = $await_9;
122 return Promise.resolve(stubbedLoad({ plugins: ['example', '@scope/example'] }, { cwd })).then(function ($await_10) {
123 try {
124 actual = $await_10;
125
126 t.deepEqual(actual.plugins, {
127 example: plugin,
128 '@scope/example': scopedPlugin
129 });
130 return $return();
131 } catch ($boundEx) {
132 return $error($boundEx);
133 }
134 }.bind(this), $error);
135 } catch ($boundEx) {
136 return $error($boundEx);
137 }
138 }.bind(this), $error);
139}.bind(this)));
140
141(0, _ava2.default)('plugins should be loaded from config', t => new Promise(function ($return, $error) {
142 var plugin, scopedPlugin, stubbedLoad, cwd, actual;
143 plugin = { '@global': true };
144 scopedPlugin = { '@global': true };
145 stubbedLoad = proxyquire('.', {
146 'commitlint-plugin-example': plugin,
147 '@scope/commitlint-plugin-example': scopedPlugin
148 });
149 return Promise.resolve(_test.git.bootstrap('fixtures/extends-plugins')).then(function ($await_11) {
150 try {
151 cwd = $await_11;
152 return Promise.resolve(stubbedLoad({}, { cwd })).then(function ($await_12) {
153 try {
154 actual = $await_12;
155
156 t.deepEqual(actual.plugins, {
157 example: plugin,
158 '@scope/example': scopedPlugin
159 });
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)('uses seed with parserPreset', t => new Promise(function ($return, $error) {
172 var cwd, _ref, actual;
173
174 return Promise.resolve(_test.git.bootstrap('fixtures/parser-preset')).then(function ($await_13) {
175 try {
176 cwd = $await_13;
177 return Promise.resolve((0, _2.default)({
178 parserPreset: './conventional-changelog-custom'
179 }, { cwd })).then(function ($await_14) {
180 try {
181 _ref = $await_14;
182 actual = _ref.parserPreset;
183
184 t.is(actual.name, './conventional-changelog-custom');
185 t.deepEqual(actual.parserOpts, {
186 headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
187 });
188 return $return();
189 } catch ($boundEx) {
190 return $error($boundEx);
191 }
192 }.bind(this), $error);
193 } catch ($boundEx) {
194 return $error($boundEx);
195 }
196 }.bind(this), $error);
197}.bind(this)));
198
199(0, _ava2.default)('uses seed with parserPreset factory', t => new Promise(function ($return, $error) {
200 var cwd, _ref2, actual;
201
202 return Promise.resolve(_test.git.bootstrap('fixtures/parser-preset-factory')).then(function ($await_15) {
203 try {
204 cwd = $await_15;
205 return Promise.resolve((0, _2.default)({
206 parserPreset: './conventional-changelog-factory'
207 }, { cwd })).then(function ($await_16) {
208 try {
209 _ref2 = $await_16;
210 actual = _ref2.parserPreset;
211
212 t.is(actual.name, './conventional-changelog-factory');
213 t.deepEqual(actual.parserOpts, {
214 headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
215 });
216 return $return();
217 } catch ($boundEx) {
218 return $error($boundEx);
219 }
220 }.bind(this), $error);
221 } catch ($boundEx) {
222 return $error($boundEx);
223 }
224 }.bind(this), $error);
225}.bind(this)));
226
227(0, _ava2.default)('invalid extend should throw', t => new Promise(function ($return, $error) {
228 var cwd;
229 return Promise.resolve(_test.git.bootstrap('fixtures/extends-invalid')).then(function ($await_17) {
230 try {
231 cwd = $await_17;
232 return Promise.resolve(t.throws((0, _2.default)({}, { cwd }))).then(function ($await_18) {
233 try {
234 return $return();
235 } catch ($boundEx) {
236 return $error($boundEx);
237 }
238 }.bind(this), $error);
239 } catch ($boundEx) {
240 return $error($boundEx);
241 }
242 }.bind(this), $error);
243}.bind(this)));
244
245(0, _ava2.default)('empty file should have no rules', t => new Promise(function ($return, $error) {
246 var cwd, actual;
247 return Promise.resolve(_test.git.bootstrap('fixtures/empty-object-file')).then(function ($await_19) {
248 try {
249 cwd = $await_19;
250 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_20) {
251 try {
252 actual = $await_20;
253
254 t.deepEqual(actual.rules, {});
255 return $return();
256 } catch ($boundEx) {
257 return $error($boundEx);
258 }
259 }.bind(this), $error);
260 } catch ($boundEx) {
261 return $error($boundEx);
262 }
263 }.bind(this), $error);
264}.bind(this)));
265
266(0, _ava2.default)('empty file should extend nothing', t => new Promise(function ($return, $error) {
267 var cwd, actual;
268 return Promise.resolve(_test.git.bootstrap('fixtures/empty-file')).then(function ($await_21) {
269 try {
270 cwd = $await_21;
271 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_22) {
272 try {
273 actual = $await_22;
274
275 t.deepEqual(actual.extends, []);
276 return $return();
277 } catch ($boundEx) {
278 return $error($boundEx);
279 }
280 }.bind(this), $error);
281 } catch ($boundEx) {
282 return $error($boundEx);
283 }
284 }.bind(this), $error);
285}.bind(this)));
286
287(0, _ava2.default)('respects cwd option', t => new Promise(function ($return, $error) {
288 var cwd, actual;
289 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends/first-extended')).then(function ($await_23) {
290 try {
291 cwd = $await_23;
292 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_24) {
293 try {
294 actual = $await_24;
295
296 t.deepEqual(actual, {
297 formatter: '@commitlint/format',
298 extends: ['./second-extended'],
299 plugins: {},
300 rules: {
301 one: 1,
302 two: 2
303 }
304 });
305 return $return();
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}.bind(this)));
315
316(0, _ava2.default)('recursive extends', t => new Promise(function ($return, $error) {
317 var cwd, actual;
318 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends')).then(function ($await_25) {
319 try {
320 cwd = $await_25;
321 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_26) {
322 try {
323 actual = $await_26;
324
325 t.deepEqual(actual, {
326 formatter: '@commitlint/format',
327 extends: ['./first-extended'],
328 plugins: {},
329 rules: {
330 zero: 0,
331 one: 1,
332 two: 2
333 }
334 });
335 return $return();
336 } catch ($boundEx) {
337 return $error($boundEx);
338 }
339 }.bind(this), $error);
340 } catch ($boundEx) {
341 return $error($boundEx);
342 }
343 }.bind(this), $error);
344}.bind(this)));
345
346(0, _ava2.default)('recursive extends with json file', t => new Promise(function ($return, $error) {
347 var cwd, actual;
348 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-json')).then(function ($await_27) {
349 try {
350 cwd = $await_27;
351 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_28) {
352 try {
353 actual = $await_28;
354
355
356 t.deepEqual(actual, {
357 formatter: '@commitlint/format',
358 extends: ['./first-extended'],
359 plugins: {},
360 rules: {
361 zero: 0,
362 one: 1,
363 two: 2
364 }
365 });
366 return $return();
367 } catch ($boundEx) {
368 return $error($boundEx);
369 }
370 }.bind(this), $error);
371 } catch ($boundEx) {
372 return $error($boundEx);
373 }
374 }.bind(this), $error);
375}.bind(this)));
376
377(0, _ava2.default)('recursive extends with yaml file', t => new Promise(function ($return, $error) {
378 var cwd, actual;
379 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-yaml')).then(function ($await_29) {
380 try {
381 cwd = $await_29;
382 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_30) {
383 try {
384 actual = $await_30;
385
386
387 t.deepEqual(actual, {
388 formatter: '@commitlint/format',
389 extends: ['./first-extended'],
390 plugins: {},
391 rules: {
392 zero: 0,
393 one: 1,
394 two: 2
395 }
396 });
397 return $return();
398 } catch ($boundEx) {
399 return $error($boundEx);
400 }
401 }.bind(this), $error);
402 } catch ($boundEx) {
403 return $error($boundEx);
404 }
405 }.bind(this), $error);
406}.bind(this)));
407
408(0, _ava2.default)('recursive extends with js file', t => new Promise(function ($return, $error) {
409 var cwd, actual;
410 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-js')).then(function ($await_31) {
411 try {
412 cwd = $await_31;
413 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_32) {
414 try {
415 actual = $await_32;
416
417
418 t.deepEqual(actual, {
419 formatter: '@commitlint/format',
420 extends: ['./first-extended'],
421 plugins: {},
422 rules: {
423 zero: 0,
424 one: 1,
425 two: 2
426 }
427 });
428 return $return();
429 } catch ($boundEx) {
430 return $error($boundEx);
431 }
432 }.bind(this), $error);
433 } catch ($boundEx) {
434 return $error($boundEx);
435 }
436 }.bind(this), $error);
437}.bind(this)));
438
439(0, _ava2.default)('recursive extends with package.json file', t => new Promise(function ($return, $error) {
440 var cwd, actual;
441 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-package')).then(function ($await_33) {
442 try {
443 cwd = $await_33;
444 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_34) {
445 try {
446 actual = $await_34;
447
448
449 t.deepEqual(actual, {
450 formatter: '@commitlint/format',
451 extends: ['./first-extended'],
452 plugins: {},
453 rules: {
454 zero: 0,
455 one: 1,
456 two: 2
457 }
458 });
459 return $return();
460 } catch ($boundEx) {
461 return $error($boundEx);
462 }
463 }.bind(this), $error);
464 } catch ($boundEx) {
465 return $error($boundEx);
466 }
467 }.bind(this), $error);
468}.bind(this)));
469
470(0, _ava2.default)('parser preset overwrites completely instead of merging', t => new Promise(function ($return, $error) {
471 var cwd, actual;
472 return Promise.resolve(_test.git.bootstrap('fixtures/parser-preset-override')).then(function ($await_35) {
473 try {
474 cwd = $await_35;
475 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_36) {
476 try {
477 actual = $await_36;
478
479 t.is(actual.parserPreset.name, './custom');
480 t.deepEqual(actual.parserPreset.parserOpts, {
481 headerPattern: /.*/
482 });
483 return $return();
484 } catch ($boundEx) {
485 return $error($boundEx);
486 }
487 }.bind(this), $error);
488 } catch ($boundEx) {
489 return $error($boundEx);
490 }
491 }.bind(this), $error);
492}.bind(this)));
493
494(0, _ava2.default)('recursive extends with parserPreset', t => new Promise(function ($return, $error) {
495 var cwd, actual;
496 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-parser-preset')).then(function ($await_37) {
497 try {
498 cwd = $await_37;
499 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_38) {
500 try {
501 actual = $await_38;
502
503 t.is(actual.parserPreset.name, './conventional-changelog-custom');
504 t.is(typeof actual.parserPreset.parserOpts, 'object');
505 t.deepEqual(actual.parserPreset.parserOpts.headerPattern, /^(\w*)(?:\((.*)\))?-(.*)$/);
506 return $return();
507 } catch ($boundEx) {
508 return $error($boundEx);
509 }
510 }.bind(this), $error);
511 } catch ($boundEx) {
512 return $error($boundEx);
513 }
514 }.bind(this), $error);
515}.bind(this)));
516
517(0, _ava2.default)('ignores unknow keys', t => new Promise(function ($return, $error) {
518 var cwd, actual;
519 return Promise.resolve(_test.git.bootstrap('fixtures/trash-file')).then(function ($await_39) {
520 try {
521 cwd = $await_39;
522 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_40) {
523 try {
524 actual = $await_40;
525
526
527 t.deepEqual(actual, {
528 formatter: '@commitlint/format',
529 extends: [],
530 plugins: {},
531 rules: {
532 foo: 'bar',
533 baz: 'bar'
534 }
535 });
536 return $return();
537 } catch ($boundEx) {
538 return $error($boundEx);
539 }
540 }.bind(this), $error);
541 } catch ($boundEx) {
542 return $error($boundEx);
543 }
544 }.bind(this), $error);
545}.bind(this)));
546
547(0, _ava2.default)('ignores unknow keys recursively', t => new Promise(function ($return, $error) {
548 var cwd, actual;
549 return Promise.resolve(_test.git.bootstrap('fixtures/trash-extend')).then(function ($await_41) {
550 try {
551 cwd = $await_41;
552 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_42) {
553 try {
554 actual = $await_42;
555
556
557 t.deepEqual(actual, {
558 formatter: '@commitlint/format',
559 extends: ['./one'],
560 plugins: {},
561 rules: {
562 zero: 0,
563 one: 1
564 }
565 });
566 return $return();
567 } catch ($boundEx) {
568 return $error($boundEx);
569 }
570 }.bind(this), $error);
571 } catch ($boundEx) {
572 return $error($boundEx);
573 }
574 }.bind(this), $error);
575}.bind(this)));
576
577(0, _ava2.default)('find up from given cwd', t => new Promise(function ($return, $error) {
578 var outer, cwd, actual;
579 return Promise.resolve(_test.fix.bootstrap('fixtures/outer-scope')).then(function ($await_43) {
580 try {
581 outer = $await_43;
582 return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_44) {
583 try {
584 cwd = _path2.default.join(outer, 'inner-scope', 'child-scope');
585 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_45) {
586 try {
587 actual = $await_45;
588
589
590 t.deepEqual(actual, {
591 formatter: '@commitlint/format',
592 extends: [],
593 plugins: {},
594 rules: {
595 child: true,
596 inner: false,
597 outer: false
598 }
599 });
600 return $return();
601 } catch ($boundEx) {
602 return $error($boundEx);
603 }
604 }.bind(this), $error);
605 } catch ($boundEx) {
606 return $error($boundEx);
607 }
608 }.bind(this), $error);
609 } catch ($boundEx) {
610 return $error($boundEx);
611 }
612 }.bind(this), $error);
613}.bind(this)));
614
615(0, _ava2.default)('find up config from outside current git repo', t => new Promise(function ($return, $error) {
616 var outer, cwd, actual;
617 return Promise.resolve(_test.fix.bootstrap('fixtures/outer-scope')).then(function ($await_46) {
618 try {
619 outer = $await_46;
620 return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_47) {
621 try {
622 cwd = $await_47;
623 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_48) {
624 try {
625 actual = $await_48;
626
627
628 t.deepEqual(actual, {
629 formatter: '@commitlint/format',
630 extends: [],
631 plugins: {},
632 rules: {
633 child: false,
634 inner: false,
635 outer: true
636 }
637 });
638 return $return();
639 } catch ($boundEx) {
640 return $error($boundEx);
641 }
642 }.bind(this), $error);
643 } catch ($boundEx) {
644 return $error($boundEx);
645 }
646 }.bind(this), $error);
647 } catch ($boundEx) {
648 return $error($boundEx);
649 }
650 }.bind(this), $error);
651}.bind(this)));
652
653(0, _ava2.default)('respects formatter option', t => new Promise(function ($return, $error) {
654 var cwd, actual;
655 return Promise.resolve(_test.git.bootstrap('fixtures/formatter')).then(function ($await_49) {
656 try {
657 cwd = $await_49;
658 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_50) {
659 try {
660 actual = $await_50;
661
662
663 t.deepEqual(actual, {
664 formatter: 'commitlint-junit',
665 extends: [],
666 plugins: {},
667 rules: {}
668 });
669 return $return();
670 } catch ($boundEx) {
671 return $error($boundEx);
672 }
673 }.bind(this), $error);
674 } catch ($boundEx) {
675 return $error($boundEx);
676 }
677 }.bind(this), $error);
678}.bind(this)));
679
680(0, _ava2.default)('resolves formatter relative from config directory', t => new Promise(function ($return, $error) {
681 var cwd, actual;
682 return Promise.resolve(_test.git.bootstrap('fixtures/formatter-local-module')).then(function ($await_51) {
683 try {
684 cwd = $await_51;
685 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_52) {
686 try {
687 actual = $await_52;
688
689
690 t.deepEqual(actual, {
691 formatter: (0, _resolveFrom2.default)(cwd, './formatters/custom.js'),
692 extends: [],
693 plugins: {},
694 rules: {}
695 });
696 return $return();
697 } catch ($boundEx) {
698 return $error($boundEx);
699 }
700 }.bind(this), $error);
701 } catch ($boundEx) {
702 return $error($boundEx);
703 }
704 }.bind(this), $error);
705}.bind(this)));
706
707(0, _ava2.default)('returns formatter name when unable to resolve from config directory', t => new Promise(function ($return, $error) {
708 var cwd, actual;
709 return Promise.resolve(_test.git.bootstrap('fixtures/formatter-local-module')).then(function ($await_53) {
710 try {
711 cwd = $await_53;
712 return Promise.resolve((0, _2.default)({ formatter: './doesnt/exists.js' }, { cwd })).then(function ($await_54) {
713 try {
714 actual = $await_54;
715
716
717 t.deepEqual(actual, {
718 formatter: './doesnt/exists.js',
719 extends: [],
720 plugins: {},
721 rules: {}
722 });
723 return $return();
724 } catch ($boundEx) {
725 return $error($boundEx);
726 }
727 }.bind(this), $error);
728 } catch ($boundEx) {
729 return $error($boundEx);
730 }
731 }.bind(this), $error);
732}.bind(this)));
733
734(0, _ava2.default)('does not mutate config module reference', t => new Promise(function ($return, $error) {
735 var file, cwd, configPath, before, after;
736 file = 'config/commitlint.config.js';
737 return Promise.resolve(_test.git.bootstrap('fixtures/specify-config-file')).then(function ($await_55) {
738 try {
739 cwd = $await_55;
740 configPath = _path2.default.join(cwd, file);
741 before = JSON.stringify(require(configPath));
742 return Promise.resolve((0, _2.default)({ arbitraryField: true }, { cwd, file })).then(function ($await_56) {
743 try {
744 after = JSON.stringify(require(configPath));
745
746
747 t.is(before, after);
748 return $return();
749 } catch ($boundEx) {
750 return $error($boundEx);
751 }
752 }.bind(this), $error);
753 } catch ($boundEx) {
754 return $error($boundEx);
755 }
756 }.bind(this), $error);
757}.bind(this)));
758//# sourceMappingURL=index.test.js.map
\No newline at end of file