From 5de2e633a538dac82aa0a488d25930744cc20246 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 29 May 2020 08:51:24 -0400 Subject: [PATCH] fix: normalize exclude option, closes #248 --- common-utils.js | 18 +++++++++++------ cypress/integration/combine-spec.js | 30 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/common-utils.js b/common-utils.js index a5711c64e..200079fa4 100644 --- a/common-utils.js +++ b/common-utils.js @@ -1,4 +1,12 @@ // @ts-check +function stringToArray(prop, obj) { + if (typeof obj[prop] === 'string') { + obj[prop] = [obj[prop]] + } + + return obj +} + function combineNycOptions({ pkgNycOptions, nycrc, @@ -14,12 +22,10 @@ function combineNycOptions({ pkgNycOptions ) - if (typeof nycOptions.reporter === 'string') { - nycOptions.reporter = [nycOptions.reporter] - } - if (typeof nycOptions.extension === 'string') { - nycOptions.extension = [nycOptions.extension] - } + // normalize string and [string] props + stringToArray('reporter', nycOptions) + stringToArray('extension', nycOptions) + stringToArray('exclude', nycOptions) return nycOptions } diff --git a/cypress/integration/combine-spec.js b/cypress/integration/combine-spec.js index 5b13ac06d..328b7c22f 100644 --- a/cypress/integration/combine-spec.js +++ b/cypress/integration/combine-spec.js @@ -63,4 +63,34 @@ describe('Combine NYC options', () => { exclude: ['bar.js'] }) }) + + it('converts exclude to array', () => { + // https://github.com/cypress-io/code-coverage/issues/248 + const pkgNycOptions = { + all: true, + extension: '.js' + } + const nycrc = { + include: ['foo.js'] + } + const nycrcJson = { + exclude: 'bar.js', + reporter: ['json'] + } + const combined = combineNycOptions({ + pkgNycOptions, + nycrc, + nycrcJson, + defaultNycOptions + }) + cy.wrap(combined).should('deep.equal', { + all: true, + 'report-dir': './coverage', + reporter: ['json'], + extension: ['.js'], + excludeAfterRemap: false, + include: ['foo.js'], + exclude: ['bar.js'] + }) + }) })