File tree 2 files changed +42
-6
lines changed
2 files changed +42
-6
lines changed Original file line number Diff line number Diff line change 1
1
// @ts -check
2
+ function stringToArray ( prop , obj ) {
3
+ if ( typeof obj [ prop ] === 'string' ) {
4
+ obj [ prop ] = [ obj [ prop ] ]
5
+ }
6
+
7
+ return obj
8
+ }
9
+
2
10
function combineNycOptions ( ...options ) {
3
11
// last option wins
4
12
const nycOptions = Object . assign ( { } , ...options )
5
13
6
- if ( typeof nycOptions . reporter === 'string' ) {
7
- nycOptions . reporter = [ nycOptions . reporter ]
8
- }
9
- if ( typeof nycOptions . extension === 'string' ) {
10
- nycOptions . extension = [ nycOptions . extension ]
11
- }
14
+ // normalize string and [string] props
15
+ stringToArray ( 'reporter' , nycOptions )
16
+ stringToArray ( 'extension' , nycOptions )
17
+ stringToArray ( 'exclude' , nycOptions )
12
18
13
19
return nycOptions
14
20
}
Original file line number Diff line number Diff line change @@ -61,4 +61,34 @@ describe('Combine NYC options', () => {
61
61
exclude : [ 'bar.js' ]
62
62
} )
63
63
} )
64
+
65
+ it ( 'converts exclude to array' , ( ) => {
66
+ // https://github.com/cypress-io/code-coverage/issues/248
67
+ const pkgNycOptions = {
68
+ all : true ,
69
+ extension : '.js'
70
+ }
71
+ const nycrc = {
72
+ include : [ 'foo.js' ]
73
+ }
74
+ const nycrcJson = {
75
+ exclude : 'bar.js' ,
76
+ reporter : [ 'json' ]
77
+ }
78
+ const combined = combineNycOptions ( {
79
+ pkgNycOptions,
80
+ nycrc,
81
+ nycrcJson,
82
+ defaultNycOptions
83
+ } )
84
+ cy . wrap ( combined ) . should ( 'deep.equal' , {
85
+ all : true ,
86
+ 'report-dir' : './coverage' ,
87
+ reporter : [ 'json' ] ,
88
+ extension : [ '.js' ] ,
89
+ excludeAfterRemap : false ,
90
+ include : [ 'foo.js' ] ,
91
+ exclude : [ 'bar.js' ]
92
+ } )
93
+ } )
64
94
} )
You can’t perform that action at this time.
0 commit comments