Skip to content

Commit e233b34

Browse files
committed
refactor a little
1 parent e87a9e3 commit e233b34

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

common-utils.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @ts-check
2+
function combineNycOptions({
3+
pkgNycOptions,
4+
nycrc,
5+
nycrcJson,
6+
defaultNycOptions
7+
}) {
8+
// last option wins
9+
const nycOptions = Object.assign(
10+
{},
11+
defaultNycOptions,
12+
nycrc,
13+
nycrcJson,
14+
pkgNycOptions
15+
)
16+
17+
if (typeof nycOptions.reporter === 'string') {
18+
nycOptions.reporter = [nycOptions.reporter]
19+
}
20+
if (typeof nycOptions.extension === 'string') {
21+
nycOptions.extension = [nycOptions.extension]
22+
}
23+
24+
return nycOptions
25+
}
26+
27+
const defaultNycOptions = {
28+
'report-dir': './coverage',
29+
reporter: ['lcov', 'clover', 'json'],
30+
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
31+
excludeAfterRemap: true
32+
}
33+
34+
module.exports = {
35+
combineNycOptions,
36+
defaultNycOptions
37+
}

cypress/integration/combine-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { combineNycOptions, defaultNycOptions } = require('../../task-utils')
1+
const { combineNycOptions, defaultNycOptions } = require('../../common-utils')
22
describe('Combine NYC options', () => {
33
it('overrides defaults', () => {
44
const pkgNycOptions = {

task-utils.js

+1-34
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,7 @@ const { isAbsolute, resolve, join } = require('path')
88
const debug = require('debug')('code-coverage')
99
const chalk = require('chalk')
1010
const globby = require('globby')
11-
12-
function combineNycOptions({
13-
pkgNycOptions,
14-
nycrc,
15-
nycrcJson,
16-
defaultNycOptions
17-
}) {
18-
// last option wins
19-
const nycOptions = Object.assign(
20-
{},
21-
defaultNycOptions,
22-
nycrc,
23-
nycrcJson,
24-
pkgNycOptions
25-
)
26-
27-
if (typeof nycOptions.reporter === 'string') {
28-
nycOptions.reporter = [nycOptions.reporter]
29-
}
30-
if (typeof nycOptions.extension === 'string') {
31-
nycOptions.extension = [nycOptions.extension]
32-
}
33-
34-
return nycOptions
35-
}
36-
37-
const defaultNycOptions = {
38-
'report-dir': './coverage',
39-
reporter: ['lcov', 'clover', 'json'],
40-
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
41-
excludeAfterRemap: true
42-
}
11+
const { combineNycOptions, defaultNycOptions } = require('./common-utils')
4312

4413
function readNycOptions(workingDirectory) {
4514
const pkgFilename = join(workingDirectory, 'package.json')
@@ -342,7 +311,5 @@ module.exports = {
342311
checkAllPathsNotFound,
343312
tryFindingLocalFiles,
344313
readNycOptions,
345-
combineNycOptions,
346-
defaultNycOptions,
347314
includeAllFiles
348315
}

0 commit comments

Comments
 (0)