Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/format/details/formatCoverageDetails.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { formatCoverageDetailsPart } from './formatCoverageDetailsPart';
import { getDecreasedCoverage } from './getDecreasedCoverage';
import { getIncreasedCoverage } from './getIncreasedCoverage';
import { getNewFilesCoverage } from './getNewFilesCoverage';
import { CoverageDetailsMap } from '../../typings/Coverage';
import { i18n } from '../../utils/i18n';
Expand All @@ -10,7 +11,7 @@ export const formatCoverageDetails = (
threshold: number | undefined
): string => {
const decreasedCoverage = getDecreasedCoverage(headDetails, baseDetails);

const increasedCoverage = getIncreasedCoverage(headDetails, baseDetails);
return [
formatCoverageDetailsPart(
i18n('newFilesCoverage'),
Expand All @@ -24,5 +25,11 @@ export const formatCoverageDetails = (
decreasedCoverage.baseDetails,
threshold
),
formatCoverageDetailsPart(
i18n('increasedCoverageFiles'),
increasedCoverage.headDetails,
increasedCoverage.baseDetails,
threshold
),
].join('\n');
};
29 changes: 29 additions & 0 deletions src/format/details/getIncreasedCoverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { CoverageDetail, CoverageDetailsMap } from '../../typings/Coverage';

const coverageGreaterThan = (first: CoverageDetail, second: CoverageDetail) =>
first.statements > second.statements ||
first.branches > second.branches ||
first.functions > second.functions;

export const getIncreasedCoverage = (
headDetails: CoverageDetailsMap,
baseDetails: CoverageDetailsMap | undefined
) =>
Object.keys(headDetails)
.filter(
(filename) =>
headDetails[filename] &&
baseDetails?.[filename] &&
coverageGreaterThan(headDetails[filename], baseDetails[filename])
)
.reduce<{
headDetails: CoverageDetailsMap;
baseDetails: CoverageDetailsMap;
}>(
(acc, filename) => {
acc.headDetails[filename] = headDetails[filename];
acc.baseDetails[filename] = baseDetails![filename];
return acc;
},
{ headDetails: {}, baseDetails: {} }
);
1 change: 1 addition & 0 deletions src/format/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"summaryTitle": "Coverage report {{ dir }}",
"newFilesCoverage": "Show new covered files :hatching_chick:",
"decreasedCoverageFiles": "Show files with reduced coverage :small_red_triangle_down:",
"increasedCoverageFiles": "Show files with increased coverage :arrow_up_small:",
"baseCoverage": "Base coverage is: ",
"loadingCoverageFromFile": "Loading code coverage from file: {{ pathToCoverageFile }}"
}
3 changes: 3 additions & 0 deletions tests/format/__snapshots__/formatCoverage.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`formatCoverage should format standard coverage 1`] = `
| 🟢 | Functions | 63.64% | 7/11 |
| 🟢 | Lines | 80.65% | 25/31 |


"
`;

Expand All @@ -29,6 +30,7 @@ exports[`formatCoverage should format standard coverage 2`] = `
| 🟢 | Functions | 63.64% | 7/11 |
| 🟢 | Lines | 80.65% | 25/31 |


"
`;

Expand All @@ -40,5 +42,6 @@ exports[`formatCoverage should format standard coverage 3`] = `
| 🟡 | Functions | 63.64% | 7/11 |
| 🟢 | Lines | 80.65% | 25/31 |


"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ exports[`getFormattedCoverage should match snapshots 1`] = `
| 🟡 | Functions | 63.64% | 7/11 |
| 🟢 | Lines | 80.65% | 25/31 |


"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ exports[`formatCoverageDetails should match snapshots 1`] = `
| :-: | :- | :- | :- | :- | :- |
| 🟡 | decreased.ts | <div title=\\"Base coverage is: 80%\\">70% (-10% 🔻)</div> | <div title=\\"Base coverage is: 60%\\">50% (-10% 🔻)</div> | <div title=\\"Base coverage is: 60%\\">50% (-10% 🔻)</div> | <div title=\\"Base coverage is: 90%\\">80% (-10% 🔻)</div> |

</details>


<details><summary>Show files with increased coverage 🔼</summary>
<br/>

| <div title=\\"Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold\\">St.<sup>:grey_question:</sup></div> | File | Statements | Branches | Functions | Lines |
| :-: | :- | :- | :- | :- | :- |
| 🟡 | increased.ts | <div title=\\"Base coverage is: 50%\\">70% (+20% 🔼)</div> | <div title=\\"Base coverage is: 30%\\">50% (+20% 🔼)</div> | <div title=\\"Base coverage is: 30%\\">50% (+20% 🔼)</div> | <div title=\\"Base coverage is: 50%\\">80% (+30% 🔼)</div> |

</details>
"
`;
88 changes: 88 additions & 0 deletions tests/format/details/getIncreasedCoverage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { getIncreasedCoverage } from '../../../src/format/details/getIncreasedCoverage';

describe('getIncreasedCoverage', () => {
it('should return files with increased coverage', () => {
expect(
getIncreasedCoverage(
{
'hello.ts': {
filename: 'hello.ts',
lines: 50,
branches: 50,
functions: 50,
statements: 50,
},
'hello2.ts': {
filename: 'hello.ts',
lines: 50,
branches: 50,
functions: 50,
statements: 50,
},
},
{
'hello.ts': {
filename: 'hello.ts',
lines: 50,
branches: 40,
functions: 50,
statements: 50,
},
'hello2.ts': {
filename: 'hello.ts',
lines: 50,
branches: 50,
functions: 50,
statements: 50,
},
}
)
).toStrictEqual({
headDetails: {
'hello.ts': {
filename: 'hello.ts',
lines: 50,
branches: 50,
functions: 50,
statements: 50,
},
},
baseDetails: {
'hello.ts': {
filename: 'hello.ts',
lines: 50,
branches: 40,
functions: 50,
statements: 50,
},
},
});
});

it('should return empty object, when base details not specified', () => {
expect(
getIncreasedCoverage(
{
'hello.ts': {
filename: 'hello.ts',
lines: 50,
branches: 50,
functions: 50,
statements: 50,
},
'hello2.ts': {
filename: 'hello.ts',
lines: 50,
branches: 50,
functions: 50,
statements: 50,
},
},
undefined
)
).toStrictEqual({
headDetails: {},
baseDetails: {},
});
});
});
4 changes: 4 additions & 0 deletions tests/stages/__snapshots__/createReport.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Object {
| 🟢 | Lines | 80.65% | 25/31 |



## Test suite run failed
Failed tests: 0/12. Failed suites: 0/5.

Expand All @@ -38,6 +39,7 @@ Object {
| 🟢 | Lines | 80.65% | 25/31 |



## Test suite run success
12 tests passing in 5 suites.

Expand All @@ -61,6 +63,7 @@ Object {
| 🟢 | Lines | 80.65% | 25/31 |



## Test suite run success
12 tests passing in 5 suites.

Expand All @@ -84,6 +87,7 @@ Object {
| 🟢 | Lines | 80.65% | 25/31 |



## Test suite run success
12 tests passing in 5 suites.

Expand Down