-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
282 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const Report = require('../report') | ||
|
||
exports.command = 'check-coverage' | ||
|
||
exports.describe = 'check whether coverage is within thresholds provided' | ||
|
||
exports.builder = function (yargs) { | ||
yargs | ||
.option('branches', { | ||
default: 0, | ||
description: 'what % of branches must be covered?' | ||
}) | ||
.option('functions', { | ||
default: 0, | ||
description: 'what % of functions must be covered?' | ||
}) | ||
.option('lines', { | ||
default: 90, | ||
description: 'what % of lines must be covered?' | ||
}) | ||
.option('statements', { | ||
default: 0, | ||
description: 'what % of statements must be covered?' | ||
}) | ||
.option('per-file', { | ||
default: false, | ||
description: 'check thresholds per file' | ||
}) | ||
.example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided") | ||
} | ||
|
||
exports.handler = function (argv) { | ||
const report = Report({ | ||
include: argv.include, | ||
exclude: argv.exclude, | ||
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter], | ||
tempDirectory: argv.tempDirectory, | ||
watermarks: argv.watermarks, | ||
resolve: argv.resolve, | ||
omitRelative: argv.omitRelative, | ||
wrapperLength: argv.wrapperLength | ||
}) | ||
const thresholds = { | ||
lines: argv.lines, | ||
functions: argv.functions, | ||
branches: argv.branches, | ||
statements: argv.statements | ||
} | ||
const map = report.getCoverageMapFromAllCoverageFiles() | ||
checkCoverages(map, thresholds, argv.perFile) | ||
} | ||
|
||
function checkCoverages (map, thresholds, perFile) { | ||
if (perFile) { | ||
map.files().forEach(file => { | ||
// ERROR: Coverage for lines (90.12%) does not meet threshold (120%) for index.js | ||
checkCoverage(map.fileCoverageFor(file).toSummary(), thresholds, file) | ||
}) | ||
} else { | ||
// ERROR: Coverage for lines (90.12%) does not meet global threshold (120%) | ||
checkCoverage(map.getCoverageSummary(), thresholds) | ||
} | ||
} | ||
|
||
function checkCoverage (summary, thresholds, file) { | ||
Object.keys(thresholds).forEach(key => { | ||
const coverage = summary[key].pct | ||
if (coverage < thresholds[key]) { | ||
process.exitCode = 1 | ||
if (file) { | ||
console.error('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet threshold (' + thresholds[key] + '%) for ' + file) | ||
} else { | ||
console.error('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds[key] + '%)') | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const Report = require('../report') | ||
|
||
exports.command = 'report' | ||
|
||
exports.describe = 'read V8 coverage data from temp and output report' | ||
|
||
exports.builder = function (yargs) {} | ||
|
||
exports.handler = function (argv) { | ||
exports.outputReport(argv) | ||
} | ||
|
||
exports.outputReport = function (argv) { | ||
const report = Report({ | ||
include: argv.include, | ||
exclude: argv.exclude, | ||
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter], | ||
tempDirectory: argv.tempDirectory, | ||
watermarks: argv.watermarks, | ||
resolve: argv.resolve, | ||
omitRelative: argv.omitRelative, | ||
wrapperLength: argv.wrapperLength | ||
}) | ||
report.run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.