Skip to content

Commit f6e2ce5

Browse files
authored
Merge branch 'master' into jreggio/support-nyc-config
2 parents 10efbf2 + 5de2e63 commit f6e2ce5

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,14 +1,20 @@
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(...options) {
311
// last option wins
412
const nycOptions = Object.assign({}, ...options)
513

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

1319
return nycOptions
1420
}

cypress/integration/combine-spec.js

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

0 commit comments

Comments
 (0)