Skip to content

Commit ae60c8d

Browse files
akoidanbahmutov
andauthored
fix: Replaced hardcoded.nyc_output string to one from config (cypress-io#332)
Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
1 parent aa62815 commit ae60c8d

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

task.js

+31-22
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const debug = require('debug')('code-coverage')
1717

1818
// these are standard folder and file names used by NYC tools
1919
const processWorkingDirectory = process.cwd()
20-
const outputFolder = '.nyc_output'
21-
const coverageFolder = join(processWorkingDirectory, outputFolder)
22-
const nycFilename = join(coverageFolder, 'out.json')
2320

2421
// there might be custom "nyc" options in the user package.json
2522
// see https://github.com/istanbuljs/nyc#configuring-nyc
@@ -33,10 +30,38 @@ const scripts = pkg.scripts || {}
3330
const DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME = 'coverage:report'
3431
const customNycReportScript = scripts[DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME]
3532

33+
const nycReportOptions = (function getNycOption() {
34+
// https://github.com/istanbuljs/nyc#common-configuration-options
35+
const nycReportOptions = readNycOptions(processWorkingDirectory)
36+
37+
if (nycReportOptions.exclude && !Array.isArray(nycReportOptions.exclude)) {
38+
console.error('NYC options: %o', nycReportOptions)
39+
throw new Error('Expected "exclude" to by an array')
40+
}
41+
42+
if (nycReportOptions['temp-dir']) {
43+
nycReportOptions['temp-dir'] = resolve(nycReportOptions['temp-dir'])
44+
} else {
45+
nycReportOptions['temp-dir'] = join(processWorkingDirectory, '.nyc_output')
46+
}
47+
48+
nycReportOptions.tempDir = nycReportOptions['temp-dir']
49+
50+
if (nycReportOptions['report-dir']) {
51+
nycReportOptions['report-dir'] = resolve(nycReportOptions['report-dir'])
52+
}
53+
// seems nyc API really is using camel cased version
54+
nycReportOptions.reportDir = nycReportOptions['report-dir']
55+
56+
return nycReportOptions
57+
})()
58+
59+
const nycFilename = join(nycReportOptions['temp-dir'], 'out.json')
60+
3661
function saveCoverage(coverage) {
37-
if (!existsSync(coverageFolder)) {
38-
mkdirSync(coverageFolder)
39-
debug('created folder %s for output coverage', coverageFolder)
62+
if (!existsSync(nycReportOptions.tempDir)) {
63+
mkdirSync(nycReportOptions.tempDir)
64+
debug('created folder %s for output coverage', nycReportOptions.tempDir)
4065
}
4166

4267
writeFileSync(nycFilename, JSON.stringify(coverage, null, 2))
@@ -164,22 +189,6 @@ const tasks = {
164189
})
165190
}
166191

167-
// https://github.com/istanbuljs/nyc#common-configuration-options
168-
const nycReportOptions = readNycOptions(processWorkingDirectory)
169-
170-
if (nycReportOptions.exclude && !Array.isArray(nycReportOptions.exclude)) {
171-
console.error('NYC options: %o', nycReportOptions)
172-
throw new Error('Expected "exclude" to by an array')
173-
}
174-
175-
// override a couple of options
176-
nycReportOptions.tempDir = coverageFolder
177-
if (nycReportOptions['report-dir']) {
178-
nycReportOptions['report-dir'] = resolve(nycReportOptions['report-dir'])
179-
}
180-
// seems nyc API really is using camel cased version
181-
nycReportOptions.reportDir = nycReportOptions['report-dir']
182-
183192
if (nycReportOptions.all) {
184193
debug('nyc needs to report on all included files')
185194
includeAllFiles(nycFilename, nycReportOptions)

0 commit comments

Comments
 (0)