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 ( {
3
11
pkgNycOptions,
4
12
nycrc,
@@ -14,12 +22,10 @@ function combineNycOptions({
14
22
pkgNycOptions
15
23
)
16
24
17
- if ( typeof nycOptions . reporter === 'string' ) {
18
- nycOptions . reporter = [ nycOptions . reporter ]
19
- }
20
- if ( typeof nycOptions . extension === 'string' ) {
21
- nycOptions . extension = [ nycOptions . extension ]
22
- }
25
+ // normalize string and [string] props
26
+ stringToArray ( 'reporter' , nycOptions )
27
+ stringToArray ( 'extension' , nycOptions )
28
+ stringToArray ( 'exclude' , nycOptions )
23
29
24
30
return nycOptions
25
31
}
Original file line number Diff line number Diff line change @@ -63,4 +63,34 @@ describe('Combine NYC options', () => {
63
63
exclude : [ 'bar.js' ]
64
64
} )
65
65
} )
66
+
67
+ it ( 'converts exclude to array' , ( ) => {
68
+ // https://github.com/cypress-io/code-coverage/issues/248
69
+ const pkgNycOptions = {
70
+ all : true ,
71
+ extension : '.js'
72
+ }
73
+ const nycrc = {
74
+ include : [ 'foo.js' ]
75
+ }
76
+ const nycrcJson = {
77
+ exclude : 'bar.js' ,
78
+ reporter : [ 'json' ]
79
+ }
80
+ const combined = combineNycOptions ( {
81
+ pkgNycOptions,
82
+ nycrc,
83
+ nycrcJson,
84
+ defaultNycOptions
85
+ } )
86
+ cy . wrap ( combined ) . should ( 'deep.equal' , {
87
+ all : true ,
88
+ 'report-dir' : './coverage' ,
89
+ reporter : [ 'json' ] ,
90
+ extension : [ '.js' ] ,
91
+ excludeAfterRemap : false ,
92
+ include : [ 'foo.js' ] ,
93
+ exclude : [ 'bar.js' ]
94
+ } )
95
+ } )
66
96
} )
You can’t perform that action at this time.
0 commit comments