Skip to content

Commit 5de2e63

Browse files
committed
fix: normalize exclude option, closes cypress-io#248
1 parent 684efec commit 5de2e63

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

common-utils.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// @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+
210
function combineNycOptions({
311
pkgNycOptions,
412
nycrc,
@@ -14,12 +22,10 @@ function combineNycOptions({
1422
pkgNycOptions
1523
)
1624

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)
2329

2430
return nycOptions
2531
}

cypress/integration/combine-spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,34 @@ describe('Combine NYC options', () => {
6363
exclude: ['bar.js']
6464
})
6565
})
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+
})
6696
})

0 commit comments

Comments
 (0)