From 09196458a2373c28a591297730e34474e50076f8 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 7 Nov 2020 17:48:27 +0200 Subject: [PATCH 1/3] Get temp-dir from config instead of hardcore --- task.js | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/task.js b/task.js index 39990b26..151cd169 100644 --- a/task.js +++ b/task.js @@ -12,14 +12,12 @@ const { includeAllFiles } = require('./task-utils') const { fixSourcePaths } = require('./support-utils') +const NYC = require('nyc') const debug = require('debug')('code-coverage') // these are standard folder and file names used by NYC tools const processWorkingDirectory = process.cwd() -const outputFolder = '.nyc_output' -const coverageFolder = join(processWorkingDirectory, outputFolder) -const nycFilename = join(coverageFolder, 'out.json') // there might be custom "nyc" options in the user package.json // see https://github.com/istanbuljs/nyc#configuring-nyc @@ -33,10 +31,40 @@ const scripts = pkg.scripts || {} const DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME = 'coverage:report' const customNycReportScript = scripts[DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME] +const nycReportOptions = (function getNycOption() { + + // https://github.com/istanbuljs/nyc#common-configuration-options + const nycReportOptions = readNycOptions(processWorkingDirectory) + + if (nycReportOptions.exclude && !Array.isArray(nycReportOptions.exclude)) { + console.error('NYC options: %o', nycReportOptions) + throw new Error('Expected "exclude" to by an array') + } + + if (nycReportOptions['temp-dir']) { + nycReportOptions['temp-dir'] = resolve(nycReportOptions['temp-dir']) + } else { + nycReportOptions['temp-dir'] = join(processWorkingDirectory, '.nyc_output') + } + + nycReportOptions.tempDir = nycReportOptions['temp-dir'] + + if (nycReportOptions['report-dir']) { + nycReportOptions['report-dir'] = resolve(nycReportOptions['report-dir']) + } + // seems nyc API really is using camel cased version + nycReportOptions.reportDir = nycReportOptions['report-dir'] + + return nycReportOptions; +})(); + +const nycFilename = join(nycReportOptions['temp-dir'], 'out.json') + + function saveCoverage(coverage) { - if (!existsSync(coverageFolder)) { - mkdirSync(coverageFolder) - debug('created folder %s for output coverage', coverageFolder) + if (!existsSync(nycReportOptions.tempDir)) { + mkdirSync(nycReportOptions.tempDir) + debug('created folder %s for output coverage', nycReportOptions.tempDir) } writeFileSync(nycFilename, JSON.stringify(coverage, null, 2)) @@ -164,21 +192,7 @@ const tasks = { }) } - // https://github.com/istanbuljs/nyc#common-configuration-options - const nycReportOptions = readNycOptions(processWorkingDirectory) - if (nycReportOptions.exclude && !Array.isArray(nycReportOptions.exclude)) { - console.error('NYC options: %o', nycReportOptions) - throw new Error('Expected "exclude" to by an array') - } - - // override a couple of options - nycReportOptions.tempDir = coverageFolder - if (nycReportOptions['report-dir']) { - nycReportOptions['report-dir'] = resolve(nycReportOptions['report-dir']) - } - // seems nyc API really is using camel cased version - nycReportOptions.reportDir = nycReportOptions['report-dir'] if (nycReportOptions.all) { debug('nyc needs to report on all included files') @@ -187,7 +201,6 @@ const tasks = { debug('calling NYC reporter with options %o', nycReportOptions) debug('current working directory is %s', process.cwd()) - const NYC = require('nyc') const nyc = new NYC(nycReportOptions) const returnReportFolder = () => { From 8d2eb3ef7258139c87847732217fef9532552953 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 7 Nov 2020 17:50:34 +0200 Subject: [PATCH 2/3] Update task.js --- task.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.js b/task.js index 151cd169..0d1e0caa 100644 --- a/task.js +++ b/task.js @@ -12,7 +12,6 @@ const { includeAllFiles } = require('./task-utils') const { fixSourcePaths } = require('./support-utils') -const NYC = require('nyc') const debug = require('debug')('code-coverage') @@ -201,6 +200,7 @@ const tasks = { debug('calling NYC reporter with options %o', nycReportOptions) debug('current working directory is %s', process.cwd()) + const NYC = require('nyc') const nyc = new NYC(nycReportOptions) const returnReportFolder = () => { From d13b0858f1b15c686f559ec0932b2adb8362fd6f Mon Sep 17 00:00:00 2001 From: Andrew Koidan Date: Sat, 7 Nov 2020 17:59:55 +0200 Subject: [PATCH 3/3] Pretty --- task.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/task.js b/task.js index 0d1e0caa..b72e2b1c 100644 --- a/task.js +++ b/task.js @@ -31,7 +31,6 @@ const DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME = 'coverage:report' const customNycReportScript = scripts[DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME] const nycReportOptions = (function getNycOption() { - // https://github.com/istanbuljs/nyc#common-configuration-options const nycReportOptions = readNycOptions(processWorkingDirectory) @@ -54,12 +53,11 @@ const nycReportOptions = (function getNycOption() { // seems nyc API really is using camel cased version nycReportOptions.reportDir = nycReportOptions['report-dir'] - return nycReportOptions; -})(); + return nycReportOptions +})() const nycFilename = join(nycReportOptions['temp-dir'], 'out.json') - function saveCoverage(coverage) { if (!existsSync(nycReportOptions.tempDir)) { mkdirSync(nycReportOptions.tempDir) @@ -191,8 +189,6 @@ const tasks = { }) } - - if (nycReportOptions.all) { debug('nyc needs to report on all included files') includeAllFiles(nycFilename, nycReportOptions)