-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlcov-runner.unit.test.ts
More file actions
139 lines (128 loc) · 3.34 KB
/
lcov-runner.unit.test.ts
File metadata and controls
139 lines (128 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { vol } from 'memfs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { ui } from '@code-pushup/utils';
import { parseLcovFiles } from './lcov-runner.js';
describe('parseLcovFiles', () => {
const UTILS_REPORT = `
TN:
SF:${path.join('common', 'utils.ts')}
FNF:0
FNH:0
DA:1,1
DA:2,0
LF:2
LH:1
BRDA:1,0,0,6
BRF:1
BRH:1
end_of_record
`;
const CONSTANTS_REPORT = `
TN:
SF:${path.join('src', 'lib', 'constants.ts')}
FNF:0
FNH:0
DA:1,1
LF:1
LH:1
BRF:0
BRH:0
end_of_record
`;
const PYTEST_REPORT = `
TN:
SF:kw/__init__.py
DA:1,1,gG9L/J2A/IwO9tZM1raZxQ
DA:0,0,gG9L/J2A/IwO9tZM1raZxQ
LF:2
LH:3
BRF:0
BRH:0
end_of_record
`;
beforeEach(() => {
vol.fromJSON(
{
[path.join('integration-tests', 'lcov.info')]: UTILS_REPORT, // file name value under SF used in tests
[path.join('unit-tests', 'lcov.info')]: CONSTANTS_REPORT, // file name value under SF used in tests
[path.join('pytest', 'lcov.info')]: PYTEST_REPORT,
'lcov.info': '', // empty report file
},
'coverage',
);
});
it('should identify coverage path passed as a string', async () => {
await expect(
parseLcovFiles([path.join('coverage', 'integration-tests', 'lcov.info')]),
).resolves.toEqual([
expect.objectContaining({ file: path.join('common', 'utils.ts') }),
]);
});
it('should identify coverage path passed as an object and prepend project path to LCOV report', async () => {
await expect(
parseLcovFiles([
{
resultsPath: path.join('coverage', 'unit-tests', 'lcov.info'),
pathToProject: path.join('packages', 'cli'),
},
]),
).resolves.toEqual([
expect.objectContaining({
file: path.join('packages', 'cli', 'src', 'lib', 'constants.ts'),
}),
]);
});
it('should correctly identify a mix of coverage path formats', async () => {
await expect(
parseLcovFiles([
{
resultsPath: path.join('coverage', 'unit-tests', 'lcov.info'),
pathToProject: path.join('packages', 'cli'),
},
path.join('coverage', 'integration-tests', 'lcov.info'),
]),
).resolves.toEqual([
expect.objectContaining({
file: path.join('packages', 'cli', 'src', 'lib', 'constants.ts'),
}),
expect.objectContaining({
file: path.join('common', 'utils.ts'),
}),
]);
});
it('should throw for only empty reports', async () => {
await expect(() =>
parseLcovFiles([path.join('coverage', 'lcov.info')]),
).rejects.toThrow('All provided coverage results are empty.');
});
it('should warn about an empty lcov file', async () => {
await parseLcovFiles([
path.join('coverage', 'integration-tests', 'lcov.info'),
path.join('coverage', 'lcov.info'),
]);
expect(ui()).toHaveLogged(
'warn',
`Coverage plugin: Empty lcov report file detected at ${path.join(
'coverage',
'lcov.info',
)}.`,
);
});
it('should skip lines numbered 0', async () => {
await expect(
parseLcovFiles([path.join('coverage', 'pytest', 'lcov.info')]),
).resolves.toEqual([
expect.objectContaining({
lines: {
found: 2,
hit: 2, // not 3
details: [
{ hit: 1, line: 1 },
// no { hit: 0, line: 0 },
],
},
}),
]);
});
});