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

Commit a511d6e

Browse files
author
Bobby Earl
authored
Added codeCoverageThreshold property and tests (#355)
1 parent d2ebfcb commit a511d6e

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

config/karma/shared.karma.conf.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
/*jslint node: true */
22
'use strict';
33

4+
/**
5+
* Adds the necessary configuration for code coverage thresholds.
6+
* @param {*} config
7+
*/
8+
function getCoverageThreshold(skyPagesConfig) {
9+
10+
function getProperty(threshold) {
11+
return {
12+
global: {
13+
statements: threshold,
14+
branches: threshold,
15+
functions: threshold,
16+
lines: threshold
17+
}
18+
};
19+
}
20+
21+
switch (skyPagesConfig.skyux.codeCoverageThreshold) {
22+
case 'none':
23+
return getProperty(0);
24+
25+
case 'standard':
26+
return getProperty(80);
27+
28+
case 'strict':
29+
return getProperty(100);
30+
}
31+
}
32+
433
/**
534
* Common Karma configuration shared between local / CI testing.
635
* @name getConfig
@@ -43,9 +72,11 @@ function getConfig(config) {
4372
webpack: testWebpackConfig.getWebpackConfig(skyPagesConfig, argv),
4473
coverageReporter: {
4574
dir: path.join(process.cwd(), 'coverage'),
75+
check: getCoverageThreshold(skyPagesConfig),
4676
reporters: [
4777
{ type: 'json' },
48-
{ type: 'html' }
78+
{ type: 'html' },
79+
{ type: 'text-summary' }
4980
],
5081
_onWriteReport: function (collector) {
5182
return remapIstanbul.remap(collector.getFinalCoverage());

runtime/config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ export interface SkyuxConfig {
5757
app?: SkyuxConfigApp;
5858
appSettings?: any;
5959
auth?: boolean;
60-
cssPath?: string;
60+
codeCoverageThreshold?: 'none' | 'standard' | 'strict';
6161
command?: string;
6262
compileMode?: string;
63+
cssPath?: string;
6364
help?: any;
6465
host?: SkyuxConfigHost;
6566
importPath?: string;

test/config-karma-shared.spec.js

+62
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ describe('config karma shared', () => {
4646
getSkyPagesConfig: (command) => {
4747
expect(command).toBe(customCommand);
4848
done();
49+
50+
return {
51+
skyux: {}
52+
};
4953
}
5054
});
5155

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

61+
function checkCodeCoverage(configValue, threshold) {
62+
63+
mock('../config/sky-pages/sky-pages.config.js', {
64+
getSkyPagesConfig: () => ({
65+
skyux: {
66+
codeCoverageThreshold: configValue
67+
}
68+
})
69+
});
70+
71+
mock(testConfigFilename, {
72+
getWebpackConfig: () => {}
73+
});
74+
75+
mock.reRequire('../config/karma/shared.karma.conf')({
76+
set: (config) => {
77+
expect(config.coverageReporter.check).toEqual({
78+
global: {
79+
statements: threshold,
80+
branches: threshold,
81+
functions: threshold,
82+
lines: threshold
83+
}
84+
});
85+
}
86+
});
87+
}
88+
89+
it('should not add the check property when codeCoverageThreshold is not defined', () => {
90+
mock('../config/sky-pages/sky-pages.config.js', {
91+
getSkyPagesConfig: () => ({
92+
skyux: {}
93+
})
94+
});
95+
96+
mock(testConfigFilename, {
97+
getWebpackConfig: () => {}
98+
});
99+
100+
mock.reRequire('../config/karma/shared.karma.conf')({
101+
set: (config) => {
102+
expect(config.coverageReporter.check).toBeUndefined();
103+
}
104+
});
105+
});
106+
107+
it('should handle codeCoverageThreshold set to "none"', () => {
108+
checkCodeCoverage('none', 0);
109+
});
110+
111+
it('should handle codeCoverageThreshold set to "standard"', () => {
112+
checkCodeCoverage('standard', 80);
113+
});
114+
115+
it('should handle codeCoverageThreshold set to "strict"', () => {
116+
checkCodeCoverage('strict', 100);
117+
});
118+
57119
});

0 commit comments

Comments
 (0)