Skip to content

Commit d6f3369

Browse files
committed
feat(plugin-coverage): replace issues with tree
1 parent e04c307 commit d6f3369

File tree

11 files changed

+899
-410
lines changed

11 files changed

+899
-410
lines changed

e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Lines changed: 349 additions & 108 deletions
Large diffs are not rendered by default.

e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { cp } from 'node:fs/promises';
22
import path from 'node:path';
3+
import { simpleGit } from 'simple-git';
34
import { afterAll, afterEach, beforeAll } from 'vitest';
45
import { type Report, reportSchema } from '@code-pushup/models';
56
import { nxTargetProject } from '@code-pushup/test-nx-utils';
67
import {
78
E2E_ENVIRONMENTS_DIR,
89
TEST_OUTPUT_DIR,
10+
initGitRepo,
911
omitVariableReportData,
1012
teardownTestFolder,
1113
} from '@code-pushup/test-utils';
@@ -22,6 +24,8 @@ describe('PLUGIN collect report with coverage-plugin NPM package', () => {
2224

2325
beforeAll(async () => {
2426
await cp(fixtureDir, testFileDir, { recursive: true });
27+
await initGitRepo(simpleGit, { baseDir: basicDir });
28+
await initGitRepo(simpleGit, { baseDir: existingDir });
2529
});
2630

2731
afterAll(async () => {
@@ -34,24 +38,24 @@ describe('PLUGIN collect report with coverage-plugin NPM package', () => {
3438
await teardownTestFolder(path.join(existingDir, '.code-pushup'));
3539
});
3640

37-
it('should run Code coverage plugin which collects passed results and creates report.json', async () => {
41+
it('should run Code coverage plugin which runs tests and creates report.json', async () => {
3842
const { code } = await executeProcess({
3943
command: 'npx',
40-
args: ['@code-pushup/cli', 'collect', '--no-progress'],
44+
args: ['code-pushup', 'collect', '--no-progress'],
4145
cwd: basicDir,
4246
});
4347

4448
expect(code).toBe(0);
4549

46-
const report = await readJsonFile(
50+
const report = await readJsonFile<Report>(
4751
path.join(basicDir, '.code-pushup', 'report.json'),
4852
);
4953

5054
expect(() => reportSchema.parse(report)).not.toThrow();
51-
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
55+
expect(omitVariableReportData(report)).toMatchSnapshot();
5256
});
5357

54-
it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => {
58+
it('should run Code coverage plugin which parses existing lcov report and creates report.json', async () => {
5559
const { code } = await executeProcess({
5660
command: 'npx',
5761
args: ['@code-pushup/cli', 'collect', '--no-progress'],
@@ -60,11 +64,11 @@ describe('PLUGIN collect report with coverage-plugin NPM package', () => {
6064

6165
expect(code).toBe(0);
6266

63-
const report = await readJsonFile(
67+
const report = await readJsonFile<Report>(
6468
path.join(existingDir, '.code-pushup', 'report.json'),
6569
);
6670

6771
expect(() => reportSchema.parse(report)).not.toThrow();
68-
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
72+
expect(omitVariableReportData(report)).toMatchSnapshot();
6973
});
7074
});

e2e/plugin-coverage-e2e/vite.config.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from 'vite';
33
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js';
44

55
export default defineConfig({
6-
cacheDir: '../../node_modules/.vite/plugin-lighthouse-e2e',
6+
cacheDir: '../../node_modules/.vite/plugin-coverage-e2e',
77
test: {
88
reporters: ['basic'],
99
testTimeout: 40_000,

packages/plugin-coverage/src/lib/runner/lcov/__snapshots__/lcov-runner.integration.test.ts.snap

Lines changed: 218 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,68 @@ exports[`lcovResultsToAuditOutputs > should correctly convert lcov results to Au
44
[
55
{
66
"details": {
7-
"issues": [
7+
"trees": [
88
{
9-
"message": "1st branch is not taken in any test case.",
10-
"severity": "error",
11-
"source": {
12-
"file": "packages/cli/src/lib/utils.ts",
13-
"position": {
14-
"startLine": 6,
15-
},
16-
},
17-
},
18-
{
19-
"message": "1st branch is not taken in any test case.",
20-
"severity": "error",
21-
"source": {
22-
"file": "packages/cli/src/lib/utils.ts",
23-
"position": {
24-
"startLine": 10,
9+
"root": {
10+
"children": [
11+
{
12+
"children": [
13+
{
14+
"children": [
15+
{
16+
"children": [
17+
{
18+
"children": [
19+
{
20+
"name": "utils.ts",
21+
"values": {
22+
"coverage": 0.8,
23+
"missing": [
24+
{
25+
"kind": "branch",
26+
"name": "0",
27+
"startLine": 6,
28+
},
29+
{
30+
"kind": "branch",
31+
"name": "0",
32+
"startLine": 10,
33+
},
34+
],
35+
},
36+
},
37+
],
38+
"name": "lib",
39+
"values": {
40+
"coverage": 0.8,
41+
},
42+
},
43+
],
44+
"name": "src",
45+
"values": {
46+
"coverage": 0.8,
47+
},
48+
},
49+
],
50+
"name": "cli",
51+
"values": {
52+
"coverage": 0.8,
53+
},
54+
},
55+
],
56+
"name": "packages",
57+
"values": {
58+
"coverage": 0.8,
59+
},
60+
},
61+
],
62+
"name": ".",
63+
"values": {
64+
"coverage": 0.8,
2565
},
2666
},
67+
"title": "Branch coverage",
68+
"type": "coverage",
2769
},
2870
],
2971
},
@@ -34,7 +76,59 @@ exports[`lcovResultsToAuditOutputs > should correctly convert lcov results to Au
3476
},
3577
{
3678
"details": {
37-
"issues": [],
79+
"trees": [
80+
{
81+
"root": {
82+
"children": [
83+
{
84+
"children": [
85+
{
86+
"children": [
87+
{
88+
"children": [
89+
{
90+
"children": [
91+
{
92+
"name": "utils.ts",
93+
"values": {
94+
"coverage": 1,
95+
"missing": [],
96+
},
97+
},
98+
],
99+
"name": "lib",
100+
"values": {
101+
"coverage": 1,
102+
},
103+
},
104+
],
105+
"name": "src",
106+
"values": {
107+
"coverage": 1,
108+
},
109+
},
110+
],
111+
"name": "cli",
112+
"values": {
113+
"coverage": 1,
114+
},
115+
},
116+
],
117+
"name": "packages",
118+
"values": {
119+
"coverage": 1,
120+
},
121+
},
122+
],
123+
"name": ".",
124+
"values": {
125+
"coverage": 1,
126+
},
127+
},
128+
"title": "Function coverage",
129+
"type": "coverage",
130+
},
131+
],
38132
},
39133
"displayValue": "100 %",
40134
"score": 1,
@@ -43,17 +137,62 @@ exports[`lcovResultsToAuditOutputs > should correctly convert lcov results to Au
43137
},
44138
{
45139
"details": {
46-
"issues": [
140+
"trees": [
47141
{
48-
"message": "Lines 7-9 are not covered in any test case.",
49-
"severity": "warning",
50-
"source": {
51-
"file": "packages/cli/src/lib/utils.ts",
52-
"position": {
53-
"endLine": 9,
54-
"startLine": 7,
142+
"root": {
143+
"children": [
144+
{
145+
"children": [
146+
{
147+
"children": [
148+
{
149+
"children": [
150+
{
151+
"children": [
152+
{
153+
"name": "utils.ts",
154+
"values": {
155+
"coverage": 0.7,
156+
"missing": [
157+
{
158+
"endLine": 9,
159+
"startLine": 7,
160+
},
161+
],
162+
},
163+
},
164+
],
165+
"name": "lib",
166+
"values": {
167+
"coverage": 0.7,
168+
},
169+
},
170+
],
171+
"name": "src",
172+
"values": {
173+
"coverage": 0.7,
174+
},
175+
},
176+
],
177+
"name": "cli",
178+
"values": {
179+
"coverage": 0.7,
180+
},
181+
},
182+
],
183+
"name": "packages",
184+
"values": {
185+
"coverage": 0.7,
186+
},
187+
},
188+
],
189+
"name": ".",
190+
"values": {
191+
"coverage": 0.7,
55192
},
56193
},
194+
"title": "Line coverage",
195+
"type": "coverage",
57196
},
58197
],
59198
},
@@ -69,17 +208,62 @@ exports[`lcovResultsToAuditOutputs > should correctly merge all lines for covera
69208
[
70209
{
71210
"details": {
72-
"issues": [
211+
"trees": [
73212
{
74-
"message": "Lines 1-30 are not covered in any test case.",
75-
"severity": "warning",
76-
"source": {
77-
"file": "packages/cli/src/lib/index.ts",
78-
"position": {
79-
"endLine": 30,
80-
"startLine": 1,
213+
"root": {
214+
"children": [
215+
{
216+
"children": [
217+
{
218+
"children": [
219+
{
220+
"children": [
221+
{
222+
"children": [
223+
{
224+
"name": "index.ts",
225+
"values": {
226+
"coverage": 0,
227+
"missing": [
228+
{
229+
"endLine": 30,
230+
"startLine": 1,
231+
},
232+
],
233+
},
234+
},
235+
],
236+
"name": "lib",
237+
"values": {
238+
"coverage": 0,
239+
},
240+
},
241+
],
242+
"name": "src",
243+
"values": {
244+
"coverage": 0,
245+
},
246+
},
247+
],
248+
"name": "cli",
249+
"values": {
250+
"coverage": 0,
251+
},
252+
},
253+
],
254+
"name": "packages",
255+
"values": {
256+
"coverage": 0,
257+
},
258+
},
259+
],
260+
"name": ".",
261+
"values": {
262+
"coverage": 0,
81263
},
82264
},
265+
"title": "Line coverage",
266+
"type": "coverage",
83267
},
84268
],
85269
},

0 commit comments

Comments
 (0)