This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Use the remapped code coverage summary for code coverage threshold check #499
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1d7d945
Use the remapped code coverage summary for code coverage threshold check
Blackbaud-PaulCrowder 03ead5f
Fixed lint rule
Blackbaud-PaulCrowder fceee83
Unit tests
Blackbaud-PaulCrowder ae0e7a9
Removed redundant const
Blackbaud-PaulCrowder 18f1e64
Validate that done() called
Blackbaud-PaulCrowder b5bd645
Be explicit about whether test should pass coverage threshold check
Blackbaud-PaulCrowder d044bad
Fixed lint error
Blackbaud-PaulCrowder 83e532e
Merge branch 'master' into code-coverage-threshold-fix
Blackbaud-PaulCrowder d761ca1
Merge branch 'master' into code-coverage-threshold-fix
Blackbaud-SteveBrush 6f823ca
Report coverage inside _onWriteReport() since _onExit() doesn't get c…
Blackbaud-PaulCrowder 48e1408
Merge branch 'code-coverage-threshold-fix' of https://github.com/blac…
Blackbaud-PaulCrowder 620595b
Minor refactoring
Blackbaud-PaulCrowder 86a71ac
Fixed linting error.
8f23486
Use function expression for consistency
Blackbaud-PaulCrowder 1b5950f
Changed `let` to`const` where appropriate
Blackbaud-PaulCrowder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,27 +8,15 @@ const logger = require('@blackbaud/skyux-logger'); | |
* @param {*} config | ||
*/ | ||
function getCoverageThreshold(skyPagesConfig) { | ||
|
||
function getProperty(threshold) { | ||
return { | ||
global: { | ||
statements: threshold, | ||
branches: threshold, | ||
functions: threshold, | ||
lines: threshold | ||
} | ||
}; | ||
} | ||
|
||
switch (skyPagesConfig.skyux.codeCoverageThreshold) { | ||
case 'none': | ||
return getProperty(0); | ||
return 0; | ||
|
||
case 'standard': | ||
return getProperty(80); | ||
return 80; | ||
|
||
case 'strict': | ||
return getProperty(100); | ||
return 100; | ||
} | ||
} | ||
|
||
|
@@ -47,6 +35,8 @@ function getConfig(config) { | |
let testWebpackConfig = require('../webpack/test.webpack.config'); | ||
let remapIstanbul = require('remap-istanbul'); | ||
|
||
const utils = require('istanbul').utils; | ||
|
||
// See minimist documentation regarding `argv._` https://github.com/substack/minimist | ||
let skyPagesConfig = require('../sky-pages/sky-pages.config').getSkyPagesConfig(argv._[0]); | ||
|
||
|
@@ -58,6 +48,8 @@ function getConfig(config) { | |
preprocessors[specBundle] = ['coverage', 'webpack', 'sourcemap']; | ||
preprocessors[specStyles] = ['webpack']; | ||
|
||
let remapCoverageSummary; | ||
|
||
config.set({ | ||
basePath: '', | ||
frameworks: ['jasmine'], | ||
|
@@ -77,15 +69,71 @@ function getConfig(config) { | |
webpack: testWebpackConfig.getWebpackConfig(skyPagesConfig, argv), | ||
coverageReporter: { | ||
dir: path.join(process.cwd(), 'coverage'), | ||
check: getCoverageThreshold(skyPagesConfig), | ||
reporters: [ | ||
{ type: 'json' }, | ||
{ type: 'html' }, | ||
{ type: 'text-summary' }, | ||
{ type: 'lcov' } | ||
{ type: 'lcov' }, | ||
{ type: 'in-memory' } | ||
], | ||
_onWriteReport: function (collector) { | ||
return remapIstanbul.remap(collector.getFinalCoverage()); | ||
const newCollector = remapIstanbul.remap(collector.getFinalCoverage()); | ||
|
||
if (!remapCoverageSummary) { | ||
// Cache the remapped coverage summary so we can evaluate it in the _onExit() hook. | ||
let summaries = []; | ||
|
||
newCollector.files().forEach((file) => { | ||
summaries.push( | ||
utils.summarizeFileCoverage( | ||
newCollector.fileCoverageFor(file) | ||
) | ||
); | ||
}); | ||
|
||
remapCoverageSummary = utils.mergeSummaryObjects.apply(null, summaries); | ||
} | ||
|
||
return newCollector; | ||
}, | ||
|
||
_onExit: function (done) { | ||
const threshold = getCoverageThreshold(skyPagesConfig); | ||
|
||
if (threshold) { | ||
// The karma-coverage library does not use the coverage summary from the remapped source | ||
// code, so its built-in code coverage check uses numbers that don't match what's reported | ||
// to the user. This will use the coverage summary generated from the remapped | ||
// source code. | ||
var keys = [ | ||
'statements', | ||
'branches', | ||
'lines', | ||
'functions' | ||
]; | ||
|
||
const threshold = getCoverageThreshold(skyPagesConfig); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t believe this line is needed twice. |
||
|
||
let coverageFailed; | ||
|
||
keys.forEach(function (key) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to not use fat arrow here? |
||
var actual = remapCoverageSummary[key].pct; | ||
|
||
if (actual < threshold) { | ||
coverageFailed = true; | ||
logger.error( | ||
`Coverage for ${key} (${actual}%) does not meet global threshold (${threshold}%)` | ||
); | ||
} | ||
}); | ||
|
||
if (coverageFailed) { | ||
logger.info(`Karma has exited with 1.`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
done(); | ||
} | ||
}, | ||
webpackServer: { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any concern on how this might affect multiple browsers? My concern is that the first result will be returned for all subsequent calls, even though they may be different browsers with different coverage.