Skip to content

Commit 652e646

Browse files
Add current coverage alongside diff to file information in table (#8)
* Added total to file coverage table * Updated README with current table view * Removed unused imports * Prettier fixes * Jest config test environment node Co-authored-by: alexandru.sirbu <[email protected]>
1 parent be85e7a commit 652e646

14 files changed

+1970
-1420
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## What it does
44

5-
* Accepts base-summary.json and head-summary.json
6-
* Diffs the two jsons and outputs info about
7-
* Percentage of changed coverage (in changed/added files)
8-
* Formatted as markdown table
9-
* Fail if coverage decreases on a file (check on percentage) for any of the lines/func/statements/branches. Can
5+
- Accepts base-summary.json and head-summary.json
6+
- Diffs the two jsons and outputs info about
7+
- Percentage of changed coverage (in changed/added files)
8+
- Formatted as markdown table
9+
- Fail if coverage decreases on a file (check on percentage) for any of the lines/func/statements/branches. Can
1010
 be configured to only check some criteria.
11-
* Written in Typescript
11+
- Written in Typescript
1212

1313
## Usage
1414

@@ -27,10 +27,10 @@ console.log(diff.regression);
2727

2828
Out:
2929

30-
| File | LinesΔ(%) | FunctionsΔ(%) | Ok |
31-
| ------ | --------- | ------------- | --- |
32-
| file_1 | 80.2 | 80.2 | |
33-
| file_2 | -2 | -2 | 🔴 |
30+
| Ok | File | Lines | Branches | Functions | Statements |
31+
| --- | ----- | ------------- | ------------- | ------------ | ------------- |
32+
| 🔴 | file1 | 80%<br>(+10%) | 14%<br>(-30%) | 3%<br>(+20%) | 20%<br>(-10%) |
33+
| | file2 | 20%<br>(+10%) | 8%<br>(-30%) | 2%<br>(-20%) | 5%<br>(-10%) |
3434

3535
API at https://flaviusone.github.io/coverage-diff/globals.html#diff
3636

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ module.exports = {
77
'^.+\\.(js|ts)$': 'ts-jest'
88
},
99
testMatch: ['**/?(*.)test.(js|ts)'],
10+
testEnvironment: 'node',
1011
moduleFileExtensions: ['ts', 'js', 'json']
1112
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coverage-diff",
3-
"version": "1.5.2",
3+
"version": "1.6.0",
44
"description": "Reports differences between two istanbul JSON code coverage summaries.",
55
"main": "lib/index",
66
"types": "lib/index",
@@ -31,14 +31,14 @@
3131
"devDependencies": {
3232
"@types/jest": "22.2.3",
3333
"@types/node": "9.6.2",
34-
"eslint": "4.19.1",
34+
"eslint": "6.7.2",
3535
"eslint-config-prettier": "2.9.0",
3636
"eslint-plugin-typescript": "0.11.0",
3737
"gh-pages": "1.1.0",
3838
"husky": "0.14.3",
3939
"jest": "22.4.3",
4040
"lint-staged": "7.0.4",
41-
"prettier": "1.11.1",
41+
"prettier": "1.19.1",
4242
"ts-jest": "22.4.3",
4343
"typedoc": "0.11.1",
4444
"typescript": "2.8.1",

src/__mocks__/diffChecker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export const diffChecker = () => ({
22
diff: 'mocked diff',
33
regression: 'mockedRegression',
44
files: 'mockedFiles',
5-
totals: { deltas: 'mockedTotals' }
5+
totals: { deltas: 'mockedTotals', pcts: 'mockedPcts' }
66
});

src/__snapshots__/diffChecker.test.ts.snap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ Object {
6565
"lines": -50,
6666
"statements": -50,
6767
},
68+
"pcts": Object {
69+
"branches": 50,
70+
"functions": 50,
71+
"lines": 50,
72+
"statements": 50,
73+
},
6874
},
6975
},
7076
"regression": false,
@@ -76,6 +82,12 @@ Object {
7682
"lines": -50,
7783
"statements": -50,
7884
},
85+
"pcts": Object {
86+
"branches": 50,
87+
"functions": 50,
88+
"lines": 50,
89+
"statements": 50,
90+
},
7991
},
8092
}
8193
`;
@@ -145,6 +157,12 @@ Object {
145157
"lines": -100,
146158
"statements": -100,
147159
},
160+
"pcts": Object {
161+
"branches": 0,
162+
"functions": 0,
163+
"lines": 0,
164+
"statements": 0,
165+
},
148166
},
149167
},
150168
"regression": true,
@@ -156,6 +174,12 @@ Object {
156174
"lines": -100,
157175
"statements": -100,
158176
},
177+
"pcts": Object {
178+
"branches": 0,
179+
"functions": 0,
180+
"lines": 0,
181+
"statements": 0,
182+
},
159183
},
160184
}
161185
`;
@@ -225,6 +249,12 @@ Object {
225249
"lines": 100,
226250
"statements": 100,
227251
},
252+
"pcts": Object {
253+
"branches": 100,
254+
"functions": 100,
255+
"lines": 100,
256+
"statements": 100,
257+
},
228258
},
229259
},
230260
"regression": false,
@@ -236,6 +266,12 @@ Object {
236266
"lines": 100,
237267
"statements": 100,
238268
},
269+
"pcts": Object {
270+
"branches": 100,
271+
"functions": 100,
272+
"lines": 100,
273+
"statements": 100,
274+
},
239275
},
240276
}
241277
`;
@@ -305,6 +341,12 @@ Object {
305341
"lines": 50,
306342
"statements": 0,
307343
},
344+
"pcts": Object {
345+
"branches": 50,
346+
"functions": 50,
347+
"lines": 100,
348+
"statements": 50,
349+
},
308350
},
309351
},
310352
"regression": false,
@@ -316,6 +358,12 @@ Object {
316358
"lines": 0,
317359
"statements": 0,
318360
},
361+
"pcts": Object {
362+
"branches": 0,
363+
"functions": 0,
364+
"lines": 0,
365+
"statements": 0,
366+
},
319367
},
320368
}
321369
`;
@@ -386,6 +434,12 @@ Object {
386434
"lines": 0,
387435
"statements": 0,
388436
},
437+
"pcts": Object {
438+
"branches": 0,
439+
"functions": 0,
440+
"lines": 0,
441+
"statements": 0,
442+
},
389443
},
390444
}
391445
`;

src/__snapshots__/resultFormatter.test.ts.snap

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

33
exports[`resultFormatter should format files results as markdown table 1`] = `
4-
"| Ok | File | LinesΔ | BranchesΔ | FunctionsΔ | StatementsΔ |
5-
| --- | ----- | ------ | --------- | ---------- | ----------- |
6-
| 🔴 | file1 | +10% | -30% | +20% | -10% |
7-
| ✅ | file2 | +10% | +30% | +20% | +10% |
4+
"| Ok | File | Lines | Branches | Functions | Statements |
5+
| --- | ----- | ------------- | ------------- | ------------ | ------------- |
6+
| 🔴 | file1 | 80%<br>(+10%) | 14%<br>(-30%) | 3%<br>(+20%) | 20%<br>(-10%) |
7+
| ✅ | file2 | 20%<br>(+10%) | 8%<br>(+30%) | 2%<br>(+20%) | 5%<br>(+10%) |
88
99
Total:
1010

src/common.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ export interface IFilesResults {
4949
}
5050

5151
export interface IFileResultFormat {
52-
deltas: {
53-
lines: number;
54-
functions: number;
55-
statements: number;
56-
branches: number;
57-
};
52+
deltas: IFileResultFields;
53+
pcts: IFileResultFields;
5854
decreased: boolean;
5955
}
6056

61-
export interface ITotalResultFormat extends IFileResultFormat {
62-
totals: ICoverageSummary;
57+
export interface IFileResultFields {
58+
lines: number;
59+
functions: number;
60+
statements: number;
61+
branches: number;
6362
}

src/diffChecker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const diffChecker = (
5656
deltas: {
5757
...diffPercentages
5858
},
59+
pcts: getSummaryPercentages(head[k]),
5960
decreased
6061
});
6162
}
@@ -66,6 +67,7 @@ export const diffChecker = (
6667
if (!totals) {
6768
totals = {
6869
deltas: { lines: 0, functions: 0, statements: 0, branches: 0 },
70+
pcts: { lines: 0, functions: 0, statements: 0, branches: 0 },
6971
decreased: false
7072
};
7173
}

src/helpers.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { objectToMap, mapToObject } from './helpers';
33
const myObject = {
44
foo: 'bar'
55
};
6-
7-
const myMap = new Map([['foo', 'bar'], ['bar', 'foo']]);
6+
const myMap = new Map([
7+
['foo', 'bar'],
8+
['bar', 'foo']
9+
]);
810

911
describe('helpers', () => {
1012
describe('objectToMap', () => {

src/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('diff', () => {
3030

3131
it('should call the resultFormatter module', () => {
3232
expect(resultFormatterSpy).toHaveBeenCalledWith('mockedFiles', {
33-
totals: fileFullCovered.total,
34-
deltas: 'mockedTotals'
33+
deltas: 'mockedTotals',
34+
pcts: 'mockedPcts'
3535
});
3636
});
3737

0 commit comments

Comments
 (0)