UNPKG

20.5 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)('invalid extend should throw', t => new Promise(function ($return, $error) {
200 var cwd;
201 return Promise.resolve(_test.git.bootstrap('fixtures/extends-invalid')).then(function ($await_15) {
202 try {
203 cwd = $await_15;
204 return Promise.resolve(t.throws((0, _2.default)({}, { cwd }))).then(function ($await_16) {
205 try {
206 return $return();
207 } catch ($boundEx) {
208 return $error($boundEx);
209 }
210 }.bind(this), $error);
211 } catch ($boundEx) {
212 return $error($boundEx);
213 }
214 }.bind(this), $error);
215}.bind(this)));
216
217(0, _ava2.default)('empty file should have no rules', t => new Promise(function ($return, $error) {
218 var cwd, actual;
219 return Promise.resolve(_test.git.bootstrap('fixtures/empty-object-file')).then(function ($await_17) {
220 try {
221 cwd = $await_17;
222 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_18) {
223 try {
224 actual = $await_18;
225
226 t.deepEqual(actual.rules, {});
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)('empty file should extend nothing', t => new Promise(function ($return, $error) {
239 var cwd, actual;
240 return Promise.resolve(_test.git.bootstrap('fixtures/empty-file')).then(function ($await_19) {
241 try {
242 cwd = $await_19;
243 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_20) {
244 try {
245 actual = $await_20;
246
247 t.deepEqual(actual.extends, []);
248 return $return();
249 } catch ($boundEx) {
250 return $error($boundEx);
251 }
252 }.bind(this), $error);
253 } catch ($boundEx) {
254 return $error($boundEx);
255 }
256 }.bind(this), $error);
257}.bind(this)));
258
259(0, _ava2.default)('respects cwd option', t => new Promise(function ($return, $error) {
260 var cwd, actual;
261 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends/first-extended')).then(function ($await_21) {
262 try {
263 cwd = $await_21;
264 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_22) {
265 try {
266 actual = $await_22;
267
268 t.deepEqual(actual, {
269 formatter: '@commitlint/format',
270 extends: ['./second-extended'],
271 plugins: {},
272 rules: {
273 one: 1,
274 two: 2
275 }
276 });
277 return $return();
278 } catch ($boundEx) {
279 return $error($boundEx);
280 }
281 }.bind(this), $error);
282 } catch ($boundEx) {
283 return $error($boundEx);
284 }
285 }.bind(this), $error);
286}.bind(this)));
287
288(0, _ava2.default)('recursive extends', t => new Promise(function ($return, $error) {
289 var cwd, actual;
290 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends')).then(function ($await_23) {
291 try {
292 cwd = $await_23;
293 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_24) {
294 try {
295 actual = $await_24;
296
297 t.deepEqual(actual, {
298 formatter: '@commitlint/format',
299 extends: ['./first-extended'],
300 plugins: {},
301 rules: {
302 zero: 0,
303 one: 1,
304 two: 2
305 }
306 });
307 return $return();
308 } catch ($boundEx) {
309 return $error($boundEx);
310 }
311 }.bind(this), $error);
312 } catch ($boundEx) {
313 return $error($boundEx);
314 }
315 }.bind(this), $error);
316}.bind(this)));
317
318(0, _ava2.default)('recursive extends with json file', t => new Promise(function ($return, $error) {
319 var cwd, actual;
320 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-json')).then(function ($await_25) {
321 try {
322 cwd = $await_25;
323 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_26) {
324 try {
325 actual = $await_26;
326
327
328 t.deepEqual(actual, {
329 formatter: '@commitlint/format',
330 extends: ['./first-extended'],
331 plugins: {},
332 rules: {
333 zero: 0,
334 one: 1,
335 two: 2
336 }
337 });
338 return $return();
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}.bind(this)));
348
349(0, _ava2.default)('recursive extends with yaml file', t => new Promise(function ($return, $error) {
350 var cwd, actual;
351 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-yaml')).then(function ($await_27) {
352 try {
353 cwd = $await_27;
354 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_28) {
355 try {
356 actual = $await_28;
357
358
359 t.deepEqual(actual, {
360 formatter: '@commitlint/format',
361 extends: ['./first-extended'],
362 plugins: {},
363 rules: {
364 zero: 0,
365 one: 1,
366 two: 2
367 }
368 });
369 return $return();
370 } catch ($boundEx) {
371 return $error($boundEx);
372 }
373 }.bind(this), $error);
374 } catch ($boundEx) {
375 return $error($boundEx);
376 }
377 }.bind(this), $error);
378}.bind(this)));
379
380(0, _ava2.default)('recursive extends with js file', t => new Promise(function ($return, $error) {
381 var cwd, actual;
382 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-js')).then(function ($await_29) {
383 try {
384 cwd = $await_29;
385 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_30) {
386 try {
387 actual = $await_30;
388
389
390 t.deepEqual(actual, {
391 formatter: '@commitlint/format',
392 extends: ['./first-extended'],
393 plugins: {},
394 rules: {
395 zero: 0,
396 one: 1,
397 two: 2
398 }
399 });
400 return $return();
401 } catch ($boundEx) {
402 return $error($boundEx);
403 }
404 }.bind(this), $error);
405 } catch ($boundEx) {
406 return $error($boundEx);
407 }
408 }.bind(this), $error);
409}.bind(this)));
410
411(0, _ava2.default)('recursive extends with package.json file', t => new Promise(function ($return, $error) {
412 var cwd, actual;
413 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-extends-package')).then(function ($await_31) {
414 try {
415 cwd = $await_31;
416 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_32) {
417 try {
418 actual = $await_32;
419
420
421 t.deepEqual(actual, {
422 formatter: '@commitlint/format',
423 extends: ['./first-extended'],
424 plugins: {},
425 rules: {
426 zero: 0,
427 one: 1,
428 two: 2
429 }
430 });
431 return $return();
432 } catch ($boundEx) {
433 return $error($boundEx);
434 }
435 }.bind(this), $error);
436 } catch ($boundEx) {
437 return $error($boundEx);
438 }
439 }.bind(this), $error);
440}.bind(this)));
441
442(0, _ava2.default)('parser preset overwrites completely instead of merging', t => new Promise(function ($return, $error) {
443 var cwd, actual;
444 return Promise.resolve(_test.git.bootstrap('fixtures/parser-preset-override')).then(function ($await_33) {
445 try {
446 cwd = $await_33;
447 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_34) {
448 try {
449 actual = $await_34;
450
451 t.is(actual.parserPreset.name, './custom');
452 t.deepEqual(actual.parserPreset.parserOpts, {
453 headerPattern: /.*/
454 });
455 return $return();
456 } catch ($boundEx) {
457 return $error($boundEx);
458 }
459 }.bind(this), $error);
460 } catch ($boundEx) {
461 return $error($boundEx);
462 }
463 }.bind(this), $error);
464}.bind(this)));
465
466(0, _ava2.default)('recursive extends with parserPreset', t => new Promise(function ($return, $error) {
467 var cwd, actual;
468 return Promise.resolve(_test.git.bootstrap('fixtures/recursive-parser-preset')).then(function ($await_35) {
469 try {
470 cwd = $await_35;
471 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_36) {
472 try {
473 actual = $await_36;
474
475 t.is(actual.parserPreset.name, './conventional-changelog-custom');
476 t.is(typeof actual.parserPreset.parserOpts, 'object');
477 t.deepEqual(actual.parserPreset.parserOpts.headerPattern, /^(\w*)(?:\((.*)\))?-(.*)$/);
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}.bind(this)));
488
489(0, _ava2.default)('ignores unknow keys', t => new Promise(function ($return, $error) {
490 var cwd, actual;
491 return Promise.resolve(_test.git.bootstrap('fixtures/trash-file')).then(function ($await_37) {
492 try {
493 cwd = $await_37;
494 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_38) {
495 try {
496 actual = $await_38;
497
498
499 t.deepEqual(actual, {
500 formatter: '@commitlint/format',
501 extends: [],
502 plugins: {},
503 rules: {
504 foo: 'bar',
505 baz: 'bar'
506 }
507 });
508 return $return();
509 } catch ($boundEx) {
510 return $error($boundEx);
511 }
512 }.bind(this), $error);
513 } catch ($boundEx) {
514 return $error($boundEx);
515 }
516 }.bind(this), $error);
517}.bind(this)));
518
519(0, _ava2.default)('ignores unknow keys recursively', t => new Promise(function ($return, $error) {
520 var cwd, actual;
521 return Promise.resolve(_test.git.bootstrap('fixtures/trash-extend')).then(function ($await_39) {
522 try {
523 cwd = $await_39;
524 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_40) {
525 try {
526 actual = $await_40;
527
528
529 t.deepEqual(actual, {
530 formatter: '@commitlint/format',
531 extends: ['./one'],
532 plugins: {},
533 rules: {
534 zero: 0,
535 one: 1
536 }
537 });
538 return $return();
539 } catch ($boundEx) {
540 return $error($boundEx);
541 }
542 }.bind(this), $error);
543 } catch ($boundEx) {
544 return $error($boundEx);
545 }
546 }.bind(this), $error);
547}.bind(this)));
548
549(0, _ava2.default)('find up from given cwd', t => new Promise(function ($return, $error) {
550 var outer, cwd, actual;
551 return Promise.resolve(_test.fix.bootstrap('fixtures/outer-scope')).then(function ($await_41) {
552 try {
553 outer = $await_41;
554 return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_42) {
555 try {
556 cwd = _path2.default.join(outer, 'inner-scope', 'child-scope');
557 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_43) {
558 try {
559 actual = $await_43;
560
561
562 t.deepEqual(actual, {
563 formatter: '@commitlint/format',
564 extends: [],
565 plugins: {},
566 rules: {
567 child: true,
568 inner: false,
569 outer: false
570 }
571 });
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 } catch ($boundEx) {
582 return $error($boundEx);
583 }
584 }.bind(this), $error);
585}.bind(this)));
586
587(0, _ava2.default)('find up config from outside current git repo', t => new Promise(function ($return, $error) {
588 var outer, cwd, actual;
589 return Promise.resolve(_test.fix.bootstrap('fixtures/outer-scope')).then(function ($await_44) {
590 try {
591 outer = $await_44;
592 return Promise.resolve(_test.git.init(_path2.default.join(outer, 'inner-scope'))).then(function ($await_45) {
593 try {
594 cwd = $await_45;
595 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_46) {
596 try {
597 actual = $await_46;
598
599
600 t.deepEqual(actual, {
601 formatter: '@commitlint/format',
602 extends: [],
603 plugins: {},
604 rules: {
605 child: false,
606 inner: false,
607 outer: true
608 }
609 });
610 return $return();
611 } catch ($boundEx) {
612 return $error($boundEx);
613 }
614 }.bind(this), $error);
615 } catch ($boundEx) {
616 return $error($boundEx);
617 }
618 }.bind(this), $error);
619 } catch ($boundEx) {
620 return $error($boundEx);
621 }
622 }.bind(this), $error);
623}.bind(this)));
624
625(0, _ava2.default)('respects formatter option', t => new Promise(function ($return, $error) {
626 var cwd, actual;
627 return Promise.resolve(_test.git.bootstrap('fixtures/formatter')).then(function ($await_47) {
628 try {
629 cwd = $await_47;
630 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_48) {
631 try {
632 actual = $await_48;
633
634
635 t.deepEqual(actual, {
636 formatter: 'commitlint-junit',
637 extends: [],
638 plugins: {},
639 rules: {}
640 });
641 return $return();
642 } catch ($boundEx) {
643 return $error($boundEx);
644 }
645 }.bind(this), $error);
646 } catch ($boundEx) {
647 return $error($boundEx);
648 }
649 }.bind(this), $error);
650}.bind(this)));
651
652(0, _ava2.default)('resolves formatter relative from config directory', t => new Promise(function ($return, $error) {
653 var cwd, actual;
654 return Promise.resolve(_test.git.bootstrap('fixtures/formatter-local-module')).then(function ($await_49) {
655 try {
656 cwd = $await_49;
657 return Promise.resolve((0, _2.default)({}, { cwd })).then(function ($await_50) {
658 try {
659 actual = $await_50;
660
661
662 t.deepEqual(actual, {
663 formatter: (0, _resolveFrom2.default)(cwd, './formatters/custom.js'),
664 extends: [],
665 plugins: {},
666 rules: {}
667 });
668 return $return();
669 } catch ($boundEx) {
670 return $error($boundEx);
671 }
672 }.bind(this), $error);
673 } catch ($boundEx) {
674 return $error($boundEx);
675 }
676 }.bind(this), $error);
677}.bind(this)));
678
679(0, _ava2.default)('returns formatter name when unable to resolve from config directory', t => new Promise(function ($return, $error) {
680 var cwd, actual;
681 return Promise.resolve(_test.git.bootstrap('fixtures/formatter-local-module')).then(function ($await_51) {
682 try {
683 cwd = $await_51;
684 return Promise.resolve((0, _2.default)({ formatter: './doesnt/exists.js' }, { cwd })).then(function ($await_52) {
685 try {
686 actual = $await_52;
687
688
689 t.deepEqual(actual, {
690 formatter: './doesnt/exists.js',
691 extends: [],
692 plugins: {},
693 rules: {}
694 });
695 return $return();
696 } catch ($boundEx) {
697 return $error($boundEx);
698 }
699 }.bind(this), $error);
700 } catch ($boundEx) {
701 return $error($boundEx);
702 }
703 }.bind(this), $error);
704}.bind(this)));
705
706(0, _ava2.default)('does not mutate config module reference', t => new Promise(function ($return, $error) {
707 var file, cwd, configPath, before, after;
708 file = 'config/commitlint.config.js';
709 return Promise.resolve(_test.git.bootstrap('fixtures/specify-config-file')).then(function ($await_53) {
710 try {
711 cwd = $await_53;
712 configPath = _path2.default.join(cwd, file);
713 before = JSON.stringify(require(configPath));
714 return Promise.resolve((0, _2.default)({ arbitraryField: true }, { cwd, file })).then(function ($await_54) {
715 try {
716 after = JSON.stringify(require(configPath));
717
718
719 t.is(before, after);
720 return $return();
721 } catch ($boundEx) {
722 return $error($boundEx);
723 }
724 }.bind(this), $error);
725 } catch ($boundEx) {
726 return $error($boundEx);
727 }
728 }.bind(this), $error);
729}.bind(this)));
730//# sourceMappingURL=index.test.js.map
\No newline at end of file