@@ -5,6 +5,10 @@ import resolveFrom from 'resolve-from';
55
66import load from '.' ;
77
8+ const proxyquire = require ( 'proxyquire' )
9+ . noCallThru ( )
10+ . noPreserveCache ( ) ;
11+
812test ( 'extends-empty should have no rules' , async t => {
913 const cwd = await git . bootstrap ( 'fixtures/extends-empty' ) ;
1014 const actual = await load ( { } , { cwd} ) ;
@@ -24,6 +28,41 @@ test('rules should be loaded from specify config file', async t => {
2428 t . is ( actual . rules . foo , 'bar' ) ;
2529} ) ;
2630
31+ test ( 'plugins should be loaded from seed' , async t => {
32+ const plugin = { '@global' : true } ;
33+ const scopedPlugin = { '@global' : true } ;
34+ const stubbedLoad = proxyquire ( '.' , {
35+ 'commitlint-plugin-example' : plugin ,
36+ '@scope/commitlint-plugin-example' : scopedPlugin
37+ } ) ;
38+
39+ const cwd = await git . bootstrap ( 'fixtures/extends-empty' ) ;
40+ const actual = await stubbedLoad (
41+ { plugins : [ 'example' , '@scope/example' ] } ,
42+ { cwd}
43+ ) ;
44+ t . deepEqual ( actual . plugins , {
45+ example : plugin ,
46+ '@scope/example' : scopedPlugin
47+ } ) ;
48+ } ) ;
49+
50+ test ( 'plugins should be loaded from config' , async t => {
51+ const plugin = { '@global' : true } ;
52+ const scopedPlugin = { '@global' : true } ;
53+ const stubbedLoad = proxyquire ( '.' , {
54+ 'commitlint-plugin-example' : plugin ,
55+ '@scope/commitlint-plugin-example' : scopedPlugin
56+ } ) ;
57+
58+ const cwd = await git . bootstrap ( 'fixtures/extends-plugins' ) ;
59+ const actual = await stubbedLoad ( { } , { cwd} ) ;
60+ t . deepEqual ( actual . plugins , {
61+ example : plugin ,
62+ '@scope/example' : scopedPlugin
63+ } ) ;
64+ } ) ;
65+
2766test ( 'uses seed with parserPreset' , async t => {
2867 const cwd = await git . bootstrap ( 'fixtures/parser-preset' ) ;
2968 const { parserPreset : actual } = await load (
@@ -61,6 +100,7 @@ test('respects cwd option', async t => {
61100 t . deepEqual ( actual , {
62101 formatter : '@commitlint/format' ,
63102 extends : [ './second-extended' ] ,
103+ plugins : { } ,
64104 rules : {
65105 one : 1 ,
66106 two : 2
@@ -74,6 +114,7 @@ test('recursive extends', async t => {
74114 t . deepEqual ( actual , {
75115 formatter : '@commitlint/format' ,
76116 extends : [ './first-extended' ] ,
117+ plugins : { } ,
77118 rules : {
78119 zero : 0 ,
79120 one : 1 ,
@@ -89,6 +130,7 @@ test('recursive extends with json file', async t => {
89130 t . deepEqual ( actual , {
90131 formatter : '@commitlint/format' ,
91132 extends : [ './first-extended' ] ,
133+ plugins : { } ,
92134 rules : {
93135 zero : 0 ,
94136 one : 1 ,
@@ -104,6 +146,7 @@ test('recursive extends with yaml file', async t => {
104146 t . deepEqual ( actual , {
105147 formatter : '@commitlint/format' ,
106148 extends : [ './first-extended' ] ,
149+ plugins : { } ,
107150 rules : {
108151 zero : 0 ,
109152 one : 1 ,
@@ -119,6 +162,7 @@ test('recursive extends with js file', async t => {
119162 t . deepEqual ( actual , {
120163 formatter : '@commitlint/format' ,
121164 extends : [ './first-extended' ] ,
165+ plugins : { } ,
122166 rules : {
123167 zero : 0 ,
124168 one : 1 ,
@@ -134,6 +178,7 @@ test('recursive extends with package.json file', async t => {
134178 t . deepEqual ( actual , {
135179 formatter : '@commitlint/format' ,
136180 extends : [ './first-extended' ] ,
181+ plugins : { } ,
137182 rules : {
138183 zero : 0 ,
139184 one : 1 ,
@@ -169,6 +214,7 @@ test('ignores unknow keys', async t => {
169214 t . deepEqual ( actual , {
170215 formatter : '@commitlint/format' ,
171216 extends : [ ] ,
217+ plugins : { } ,
172218 rules : {
173219 foo : 'bar' ,
174220 baz : 'bar'
@@ -183,6 +229,7 @@ test('ignores unknow keys recursively', async t => {
183229 t . deepEqual ( actual , {
184230 formatter : '@commitlint/format' ,
185231 extends : [ './one' ] ,
232+ plugins : { } ,
186233 rules : {
187234 zero : 0 ,
188235 one : 1
@@ -200,6 +247,7 @@ test('find up from given cwd', async t => {
200247 t . deepEqual ( actual , {
201248 formatter : '@commitlint/format' ,
202249 extends : [ ] ,
250+ plugins : { } ,
203251 rules : {
204252 child : true ,
205253 inner : false ,
@@ -216,6 +264,7 @@ test('find up config from outside current git repo', async t => {
216264 t . deepEqual ( actual , {
217265 formatter : '@commitlint/format' ,
218266 extends : [ ] ,
267+ plugins : { } ,
219268 rules : {
220269 child : false ,
221270 inner : false ,
@@ -231,6 +280,7 @@ test('respects formatter option', async t => {
231280 t . deepEqual ( actual , {
232281 formatter : 'commitlint-junit' ,
233282 extends : [ ] ,
283+ plugins : { } ,
234284 rules : { }
235285 } ) ;
236286} ) ;
@@ -242,6 +292,7 @@ test('resolves formatter relative from config directory', async t => {
242292 t . deepEqual ( actual , {
243293 formatter : resolveFrom ( cwd , './formatters/custom.js' ) ,
244294 extends : [ ] ,
295+ plugins : { } ,
245296 rules : { }
246297 } ) ;
247298} ) ;
@@ -253,6 +304,7 @@ test('returns formatter name when unable to resolve from config directory', asyn
253304 t . deepEqual ( actual , {
254305 formatter : './doesnt/exists.js' ,
255306 extends : [ ] ,
307+ plugins : { } ,
256308 rules : { }
257309 } ) ;
258310} ) ;
0 commit comments