@@ -7,10 +7,12 @@ jest.mock('@scope/commitlint-plugin-example', () => scopedPlugin, {
7
7
} ) ;
8
8
9
9
import path from 'path' ;
10
+ import { readFileSync , writeFileSync } from 'fs' ;
10
11
import resolveFrom from 'resolve-from' ;
11
12
import { fix , git , npm } from '@commitlint/test' ;
12
13
13
14
import load from './load' ;
15
+ import { isDynamicAwaitSupported } from './utils/load-config' ;
14
16
15
17
const fixBootstrap = ( name : string ) => fix . bootstrap ( name , __dirname ) ;
16
18
const gitBootstrap = ( name : string ) => git . bootstrap ( name , __dirname ) ;
@@ -186,24 +188,30 @@ test('respects cwd option', async () => {
186
188
} ) ;
187
189
} ) ;
188
190
189
- test ( 'recursive extends' , async ( ) => {
190
- const cwd = await gitBootstrap ( 'fixtures/recursive-extends' ) ;
191
- const actual = await load ( { } , { cwd} ) ;
192
-
193
- expect ( actual ) . toMatchObject ( {
194
- formatter : '@commitlint/format' ,
195
- extends : [ './first-extended' ] ,
196
- plugins : { } ,
197
- rules : {
198
- zero : [ 0 , 'never' ] ,
199
- one : [ 1 , 'always' ] ,
200
- two : [ 2 , 'never' ] ,
201
- } ,
202
- } ) ;
203
- } ) ;
191
+ const mjsConfigFiles = isDynamicAwaitSupported ( )
192
+ ? [ 'commitlint.config.mjs' , '.commitlintrc.mjs' ]
193
+ : [ ] ;
194
+
195
+ test . each (
196
+ [
197
+ 'commitlint.config.cjs' ,
198
+ 'commitlint.config.js' ,
199
+ 'package.json' ,
200
+ '.commitlintrc' ,
201
+ '.commitlintrc.cjs' ,
202
+ '.commitlintrc.js' ,
203
+ '.commitlintrc.json' ,
204
+ '.commitlintrc.yml' ,
205
+ '.commitlintrc.yaml' ,
206
+ ...mjsConfigFiles ,
207
+ ] . map ( ( configFile ) => [ configFile ] )
208
+ ) ( 'recursive extends with %s' , async ( configFile ) => {
209
+ const cwd = await gitBootstrap ( `fixtures/recursive-extends-js-template` ) ;
210
+ const configPath = path . join ( __dirname , `../fixtures/config/${ configFile } ` ) ;
211
+ const config = readFileSync ( configPath ) ;
212
+
213
+ writeFileSync ( path . join ( cwd , configFile ) , config ) ;
204
214
205
- test ( 'recursive extends with json file' , async ( ) => {
206
- const cwd = await gitBootstrap ( 'fixtures/recursive-extends-json' ) ;
207
215
const actual = await load ( { } , { cwd} ) ;
208
216
209
217
expect ( actual ) . toMatchObject ( {
@@ -218,63 +226,13 @@ test('recursive extends with json file', async () => {
218
226
} ) ;
219
227
} ) ;
220
228
221
- test ( 'recursive extends with yaml file' , async ( ) => {
222
- const cwd = await gitBootstrap ( 'fixtures/recursive-extends-yaml' ) ;
223
- const actual = await load ( { } , { cwd} ) ;
224
-
225
- expect ( actual ) . toMatchObject ( {
226
- formatter : '@commitlint/format' ,
227
- extends : [ './first-extended' ] ,
228
- plugins : { } ,
229
- rules : {
230
- zero : [ 0 , 'never' ] ,
231
- one : [ 1 , 'never' ] ,
232
- two : [ 2 , 'always' ] ,
233
- } ,
234
- } ) ;
235
- } ) ;
236
-
237
- test ( 'recursive extends with js file' , async ( ) => {
238
- const cwd = await gitBootstrap ( 'fixtures/recursive-extends-js' ) ;
239
- const actual = await load ( { } , { cwd} ) ;
240
-
241
- expect ( actual ) . toMatchObject ( {
242
- formatter : '@commitlint/format' ,
243
- extends : [ './first-extended' ] ,
244
- plugins : { } ,
245
- rules : {
246
- zero : [ 0 , 'never' ] ,
247
- one : [ 1 , 'never' ] ,
248
- two : [ 2 , 'always' ] ,
249
- } ,
250
- } ) ;
251
- } ) ;
252
-
253
- test ( 'recursive extends with package.json file' , async ( ) => {
254
- const cwd = await gitBootstrap ( 'fixtures/recursive-extends-package' ) ;
255
- const actual = await load ( { } , { cwd} ) ;
256
-
257
- expect ( actual ) . toMatchObject ( {
258
- formatter : '@commitlint/format' ,
259
- extends : [ './first-extended' ] ,
260
- plugins : { } ,
261
- rules : {
262
- zero : [ 0 , 'never' ] ,
263
- one : [ 1 , 'never' ] ,
264
- two : [ 2 , 'never' ] ,
265
- } ,
266
- } ) ;
267
- } ) ;
268
-
269
- // fails since a jest update: https://github.com/conventional-changelog/commitlint/pull/3362
270
- // eslint-disable-next-line jest/no-disabled-tests
271
- test . skip ( 'recursive extends with ts file' , async ( ) => {
229
+ test ( 'recursive extends with ts file' , async ( ) => {
272
230
const cwd = await gitBootstrap ( 'fixtures/recursive-extends-ts' ) ;
273
231
const actual = await load ( { } , { cwd} ) ;
274
232
275
233
expect ( actual ) . toMatchObject ( {
276
234
formatter : '@commitlint/format' ,
277
- extends : [ './first-extended' ] ,
235
+ extends : [ './first-extended/index.ts ' ] ,
278
236
plugins : { } ,
279
237
rules : {
280
238
zero : [ 0 , 'never' , 'zero' ] ,
0 commit comments