Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Added codeCoverageThreshold property and tests #355

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added codeCoverageThreshold property and tests
  • Loading branch information
Bobby Earl committed Jan 23, 2018
commit d70277a0379cc29f0f7726d8cac48cb0cbd1db1b
33 changes: 32 additions & 1 deletion config/karma/shared.karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
/*jslint node: true */
'use strict';

/**
* Adds the necessary configuration for code coverage thresholds.
* @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);

case 'standard':
return getProperty(80);

case 'strict':
return getProperty(100);
}
}

/**
* Common Karma configuration shared between local / CI testing.
* @name getConfig
@@ -43,9 +72,11 @@ function getConfig(config) {
webpack: testWebpackConfig.getWebpackConfig(skyPagesConfig, argv),
coverageReporter: {
dir: path.join(process.cwd(), 'coverage'),
check: getCoverageThreshold(skyPagesConfig),
reporters: [
{ type: 'json' },
{ type: 'html' }
{ type: 'html' },
{ type: 'text-summary' }
],
_onWriteReport: function (collector) {
return remapIstanbul.remap(collector.getFinalCoverage());
3 changes: 2 additions & 1 deletion runtime/config.ts
Original file line number Diff line number Diff line change
@@ -57,9 +57,10 @@ export interface SkyuxConfig {
app?: SkyuxConfigApp;
appSettings?: any;
auth?: boolean;
cssPath?: string;
codeCoverageThreshold?: 'none' | 'standard' | 'strict';
command?: string;
compileMode?: string;
cssPath?: string;
help?: any;
host?: SkyuxConfigHost;
importPath?: string;
62 changes: 62 additions & 0 deletions test/config-karma-shared.spec.js
Original file line number Diff line number Diff line change
@@ -46,6 +46,10 @@ describe('config karma shared', () => {
getSkyPagesConfig: (command) => {
expect(command).toBe(customCommand);
done();

return {
skyux: {}
};
}
});

@@ -54,4 +58,62 @@ describe('config karma shared', () => {
});
});

function checkCodeCoverage(configValue, threshold) {

mock('../config/sky-pages/sky-pages.config.js', {
getSkyPagesConfig: () => ({
skyux: {
codeCoverageThreshold: configValue
}
})
});

mock(testConfigFilename, {
getWebpackConfig: () => {}
});

mock.reRequire('../config/karma/shared.karma.conf')({
set: (config) => {
expect(config.coverageReporter.check).toEqual({
global: {
statements: threshold,
branches: threshold,
functions: threshold,
lines: threshold
}
});
}
});
}

it('should not add the check property when codeCoverageThreshold is not defined', () => {
mock('../config/sky-pages/sky-pages.config.js', {
getSkyPagesConfig: () => ({
skyux: {}
})
});

mock(testConfigFilename, {
getWebpackConfig: () => {}
});

mock.reRequire('../config/karma/shared.karma.conf')({
set: (config) => {
expect(config.coverageReporter.check).toBeUndefined();
}
});
});

it('should handle codeCoverageThreshold set to "none"', () => {
checkCodeCoverage('none', 0);
});

it('should handle codeCoverageThreshold set to "standard"', () => {
checkCodeCoverage('standard', 80);
});

it('should handle codeCoverageThreshold set to "strict"', () => {
checkCodeCoverage('strict', 100);
});

});