Skip to content

Commit ee62702

Browse files
committed
add threshold-uncovered option
allows threshold to be set by number of uncovered lines instead of percentage of coverage. In a codebase which continuously grows, if you fix the number of lines uncovered then you (loosely) enforce that all new code should be covered. closes #168
1 parent ea09e05 commit ee62702

23 files changed

+6008
-38
lines changed

__tests__/integrations/cli/__snapshots__/test-exit-value.js.snap

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ Object {
77
}
88
`;
99

10+
exports[`CLI exit value should exit with code 0 when uncovered_count <= thresholdUncovered 1`] = `
11+
Object {
12+
"error": null,
13+
"exitCode": 0,
14+
}
15+
`;
16+
1017
exports[`CLI exit value should exit with code 2 when total coverage is lower than the custom threshold 1`] = `
1118
Object {
1219
"error": [Error: Command failed: flow-coverage-report.js -i "src/*.js" --threshold 22
13-
Flow Coverage 16% is below the required threshold 22%
20+
Flow Coverage: 16% is below the required threshold 22%
1421
],
1522
"exitCode": 2,
1623
}
@@ -19,7 +26,16 @@ Flow Coverage 16% is below the required threshold 22%
1926
exports[`CLI exit value should exit with code 2 when total coverage is lower than the default threshold 1`] = `
2027
Object {
2128
"error": [Error: Command failed: flow-coverage-report.js -i "src/*.js"
22-
Flow Coverage 16% is below the required threshold 80%
29+
Flow Coverage: 16% is below the required threshold 80%
30+
],
31+
"exitCode": 2,
32+
}
33+
`;
34+
35+
exports[`CLI exit value should exit with code 2 when uncovered_count > thresholdUncovered 1`] = `
36+
Object {
37+
"error": [Error: Command failed: flow-coverage-report.js -i "src/*.js" --threshold-uncovered 3
38+
Flow Coverage: uncovered count is higher than the uncoveredThreshold
2339
],
2440
"exitCode": 2,
2541
}

__tests__/integrations/cli/__snapshots__/test-percent-decimals.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
exports[`--percent-decimals option should round percent values using the requested precision 1`] = `
44
Object {
55
"error": [Error: Command failed: flow-coverage-report.js --percent-decimals 2 -i "src/**.js"
6-
Flow Coverage 16.67% is below the required threshold 80%
6+
Flow Coverage: 16.67% is below the required threshold 80%
77
],
88
"exitCode": 2,
99
"filteredStdout": Array [
1010
"│ src/main.js │ flow │ 16.67 % │ 6 │ 1 │ 5 │",
1111
"│ project-decimal-coverage │ 16.67 % │ 6 │ 1 │ 5 │",
1212
],
13-
"stderr": "Flow Coverage 16.67% is below the required threshold 80%
13+
"stderr": "Flow Coverage: 16.67% is below the required threshold 80%
1414
",
1515
}
1616
`;

__tests__/integrations/cli/__snapshots__/test-regression-issue-57.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Object {
55
"filteredStdout": Array [
66
"│ src/url.js │ flow │ 0 % │ 9 │ 0 │ 9 │",
77
],
8-
"stderr": "Flow Coverage 0% is below the required threshold 80%
8+
"stderr": "Flow Coverage: 0% is below the required threshold 80%
99
",
1010
}
1111
`;

__tests__/integrations/cli/test-exit-value.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,22 @@ describe('CLI exit value', async () => {
3535

3636
expect({exitCode, error}).toMatchSnapshot();
3737
});
38+
39+
it('should exit with code 2 when uncovered_count > thresholdUncovered', async () => {
40+
const {exitCode, error} = await runFlowCoverageReport([
41+
'-i', `"src/*.js"`,
42+
'--threshold-uncovered', '3'
43+
], {cwd: testProjectDir});
44+
45+
expect({exitCode, error}).toMatchSnapshot();
46+
});
47+
48+
it('should exit with code 0 when uncovered_count <= thresholdUncovered', async () => {
49+
const {exitCode, error} = await runFlowCoverageReport([
50+
'-i', `"src/*.js"`,
51+
'--threshold-uncovered', '10'
52+
], {cwd: testProjectDir});
53+
54+
expect({exitCode, error}).toMatchSnapshot();
55+
});
3856
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"scripts": {
1616
"ava": "nyc ava --verbose",
1717
"build": "rimraf dist && babel -d dist src --only src/lib --source-maps",
18+
"dev": "babel -d dist src --only src/lib --source-maps --watch",
1819
"update-flow-typed": "rimraf flow-typed && flow-typed install -s -i dev",
1920
"flow-coverage": "bin/flow-coverage-report.js",
2021
"flow-check": "flow check",
@@ -185,7 +186,7 @@
185186
"\\.jsx$": "babel-jest"
186187
},
187188
"transformIgnorePatterns": [
188-
"node_modules/(?!(svgo)/)"
189+
"node_modules/(?!(svgo|badge-up)/)"
189190
],
190191
"testEnvironment": "node",
191192
"testMatch": [

src/__tests__/fixtures.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const FLOW_COVERAGE_SUMMARY_DATA = {
3333
covered_count: 5,
3434
uncovered_count: 5,
3535
threshold: 40,
36+
uncoveredThreshold: 3,
3637
percent: 50,
3738
globIncludePatterns: [firstGlob, secondGlob],
3839
files: allFiles.reduce((acc, filename) => {

src/__tests__/react-components/__snapshots__/test-coverage-meter-bar.js.snap

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`<FlowCoverageMeterBar /> 1`] = `
3+
exports[`<FlowCoverageMeterBar /> percent <= threshold 1`] = `
44
<div
55
className="row red"
66
style={
@@ -11,3 +11,15 @@ exports[`<FlowCoverageMeterBar /> 1`] = `
1111
}
1212
/>
1313
`;
14+
15+
exports[`<FlowCoverageMeterBar /> uncoveredCount <= thresholdUncovered 1`] = `
16+
<div
17+
className="row green"
18+
style={
19+
Object {
20+
"height": 12,
21+
"padding": 0,
22+
}
23+
}
24+
/>
25+
`;

src/__tests__/react-components/__snapshots__/test-coverage-summary-table.js.snap

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,45 @@ exports[`<FlowCoverageSummaryTable /> 2`] = `
8383
</tbody>
8484
</table>
8585
`;
86+
87+
exports[`<FlowCoverageSummaryTable /> 3`] = `
88+
<table
89+
className="ui small celled table"
90+
>
91+
<thead>
92+
<tr>
93+
<th>
94+
Percent
95+
</th>
96+
<th>
97+
Total
98+
</th>
99+
<th>
100+
Covered
101+
</th>
102+
<th>
103+
Uncovered
104+
</th>
105+
</tr>
106+
</thead>
107+
<tbody>
108+
<tr
109+
className="positive"
110+
>
111+
<td>
112+
50
113+
%
114+
</td>
115+
<td>
116+
10
117+
</td>
118+
<td>
119+
5
120+
</td>
121+
<td>
122+
5
123+
</td>
124+
</tr>
125+
</tbody>
126+
</table>
127+
`;

src/__tests__/react-components/test-coverage-meter-bar.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ import {BASE_DIR} from './common';
99

1010
const REACT_COMPONENT = `${BASE_DIR}/coverage-meter-bar`;
1111

12-
test('<FlowCoverageMeterBar />', () => {
13-
const FlowCoverageMeterBar = require(REACT_COMPONENT).default;
14-
const props = {
15-
percent: 20,
16-
threshold: 80
17-
};
18-
const tree = renderer.create(<FlowCoverageMeterBar {...props}/>).toJSON();
19-
expect(tree).toMatchSnapshot();
12+
describe('<FlowCoverageMeterBar />', () => {
13+
test('percent <= threshold', () => {
14+
const FlowCoverageMeterBar = require(REACT_COMPONENT).default;
15+
const props = {
16+
percent: 20,
17+
threshold: 80
18+
};
19+
const tree = renderer.create(<FlowCoverageMeterBar {...props}/>).toJSON();
20+
expect(tree).toMatchSnapshot();
21+
});
22+
23+
test('uncoveredCount <= thresholdUncovered', () => {
24+
const FlowCoverageMeterBar = require(REACT_COMPONENT).default;
25+
const props = {
26+
uncoveredCount: 20,
27+
thresholdUncovered: 30
28+
};
29+
const tree = renderer.create(<FlowCoverageMeterBar {...props}/>).toJSON();
30+
expect(tree).toMatchSnapshot();
31+
});
2032
});
2133

2234
test.skip('<FlowCoverageMeterBar /> with missing props');

src/__tests__/react-components/test-coverage-summary-table.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ test('<FlowCoverageSummaryTable />', () => {
2121
const positiveSummaryTree = renderer.create(<FlowCoverageSummaryTable {...positiveSummaryProps}/>).toJSON();
2222
expect(positiveSummaryTree).toMatchSnapshot();
2323

24-
// Expect positive with higher threshold.
24+
// Expect negative with higher threshold.
2525
const negativeSummaryProps = {
2626
coverageSummaryData: {...FLOW_COVERAGE_SUMMARY_DATA, threshold: 90}
2727
};
2828
const negativeSummaryTree = renderer.create(<FlowCoverageSummaryTable {...negativeSummaryProps}/>).toJSON();
2929
expect(negativeSummaryTree).toMatchSnapshot();
30+
31+
// Expect negative with uncovered_count >= thresholdUncovered
32+
const negativeSummaryUncoveredProps = {
33+
coverageSummaryData: {...FLOW_COVERAGE_SUMMARY_DATA, uncoveredThreshold: 4}
34+
};
35+
const negativeSummaryUncoveredTree = renderer.create(<FlowCoverageSummaryTable {...negativeSummaryUncoveredProps}/>).toJSON();
36+
expect(negativeSummaryUncoveredTree).toMatchSnapshot();
3037
});
3138

3239
test.skip('<FlowCoverageSummaryTable /> with missing props');

0 commit comments

Comments
 (0)