Skip to content

Commit 3fecae9

Browse files
authored
test: split coverage e2e (#872)
1 parent 7e6c29d commit 3fecae9

File tree

20 files changed

+666
-518
lines changed

20 files changed

+666
-518
lines changed

e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Lines changed: 0 additions & 420 deletions
Large diffs are not rendered by default.

e2e/cli-e2e/tests/collect.e2e.test.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { dirname, join } from 'node:path';
2-
import { fileURLToPath } from 'node:url';
31
import {
42
type AuditReport,
53
type PluginReport,
@@ -65,59 +63,6 @@ describe('CLI collect', () => {
6563
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
6664
});
6765

68-
it('should run Code coverage plugin which collects passed results and creates report.json', async () => {
69-
/**
70-
* The stats passed in the fixture are as follows
71-
* 3 files: one partially covered, one with no coverage, one with full coverage
72-
* Functions: 2 + 1 + 2 found | 1 + 0 + 2 covered (60% coverage)
73-
* Branches: 10 + 2 + 5 found | 8 + 0 + 5 covered (76% coverage)
74-
* Lines: 10 + 5 + 10 found | 7 + 0 + 10 covered (68% coverage)
75-
*/
76-
77-
const configPath = join(
78-
fileURLToPath(dirname(import.meta.url)),
79-
'..',
80-
'mocks',
81-
'fixtures',
82-
'code-pushup.config.ts',
83-
);
84-
85-
const { code, stderr } = await executeProcess({
86-
command: 'code-pushup',
87-
args: [
88-
'collect',
89-
'--no-progress',
90-
`--config=${configPath}`,
91-
'--persist.outputDir=tmp/e2e',
92-
'--onlyPlugins=coverage',
93-
],
94-
});
95-
96-
expect(code).toBe(0);
97-
expect(stderr).toBe('');
98-
99-
const report = await readJsonFile(join('tmp', 'e2e', 'report.json'));
100-
101-
expect(() => reportSchema.parse(report)).not.toThrow();
102-
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
103-
});
104-
105-
it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => {
106-
const { code, stderr } = await executeProcess({
107-
command: 'code-pushup',
108-
args: ['collect', '--no-progress', '--onlyPlugins=coverage'],
109-
cwd: 'examples/react-todos-app',
110-
});
111-
112-
expect(code).toBe(0);
113-
expect(stderr).toBe('');
114-
115-
const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');
116-
117-
expect(() => reportSchema.parse(report)).not.toThrow();
118-
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
119-
});
120-
12166
it('should create report.md', async () => {
12267
const { code, stderr } = await executeProcess({
12368
command: 'code-pushup',
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*", "code-pushup.config*.ts"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx"],
7+
"parserOptions": {
8+
"project": ["e2e/plugin-coverage-e2e/tsconfig.*?.json"]
9+
}
10+
}
11+
]
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import coveragePlugin from '@code-pushup/coverage-plugin';
2+
3+
export default {
4+
plugins: [
5+
await coveragePlugin({
6+
reports: ['coverage/lcov.info'],
7+
coverageToolCommand: {
8+
command: 'npm',
9+
args: ['run', 'test'],
10+
},
11+
}),
12+
],
13+
categories: [
14+
{
15+
slug: 'code-coverage',
16+
title: 'Code coverage',
17+
refs: [
18+
{
19+
type: 'group',
20+
plugin: 'coverage',
21+
slug: 'coverage',
22+
weight: 1,
23+
},
24+
],
25+
},
26+
],
27+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "coverage-e2e-env",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "npx vitest run --coverage"
7+
},
8+
"keywords": [],
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
},
13+
"description": ""
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function untested() {
2+
console.log('This function is not tested');
3+
}
4+
5+
export function get42() {
6+
return 42;
7+
}
8+
9+
export function isEven(num) {
10+
if (num === undefined) {
11+
return false;
12+
}
13+
const parsedNumber = parseInt(num, 10);
14+
return parsedNumber % 2 === 0;
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { get42, isEven, untested } from './index.mjs';
3+
4+
describe('get42', () => {
5+
it('should return 42', async () => {
6+
expect(get42()).toBe(42);
7+
});
8+
});
9+
10+
describe('isEven', () => {
11+
it('should return true for even number 42', async () => {
12+
expect(isEven(42)).toBe(true);
13+
});
14+
15+
it.todo('should return false for odd number 1');
16+
});
17+
18+
describe.todo('untested', () => {});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference types="vitest" />
2+
import { dirname } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { defineConfig } from 'vite';
5+
6+
export default defineConfig({
7+
root: fileURLToPath(dirname(import.meta.url)),
8+
cacheDir: 'node_modules/.vite/coverage-e2e-env',
9+
10+
test: {
11+
reporters: ['basic'],
12+
globals: true,
13+
cache: {
14+
dir: 'node_modules/.vitest',
15+
},
16+
coverage: {
17+
reporter: ['lcov', 'text'],
18+
provider: 'v8',
19+
reportsDirectory: 'coverage',
20+
include: ['src/**/*.{js,mjs}'],
21+
},
22+
environment: 'node',
23+
include: ['src/**/*.{test,spec}.{js,mjs}'],
24+
},
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { join } from 'node:path';
2+
import coveragePlugin from '@code-pushup/coverage-plugin';
3+
import type { CoreConfig } from '@code-pushup/models';
4+
5+
export default {
6+
plugins: [
7+
await coveragePlugin({
8+
reports: [join('coverage', 'lcov.info')],
9+
}),
10+
],
11+
categories: [
12+
{
13+
slug: 'code-coverage',
14+
title: 'Code coverage',
15+
refs: [
16+
{
17+
type: 'group',
18+
plugin: 'coverage',
19+
slug: 'coverage',
20+
weight: 1,
21+
},
22+
],
23+
},
24+
],
25+
} satisfies CoreConfig;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
TN:
2+
SF:src\lib\partly-covered\utils.ts
3+
FN:2,formatReportScore
4+
FN:6,calcDuration
5+
FNF:2
6+
FNH:1
7+
FNDA:0,formatReportScore
8+
FNDA:6,calcDuration
9+
DA:1,1
10+
DA:2,1
11+
DA:3,1
12+
DA:4,1
13+
DA:5,1
14+
DA:6,1
15+
DA:7,0
16+
DA:8,0
17+
DA:9,0
18+
DA:10,1
19+
LF:10
20+
LH:7
21+
BRDA:1,0,0,6
22+
BRDA:1,1,0,5
23+
BRDA:2,4,0,1
24+
BRDA:4,5,0,17
25+
BRDA:5,6,0,4
26+
BRDA:6,7,0,13
27+
BRDA:6,10,1,0
28+
BRDA:7,11,0,3
29+
BRDA:10,12,0,12
30+
BRDA:10,13,1,0
31+
BRF:10
32+
BRH:8
33+
end_of_record
34+
SF:src\lib\not-covered\sorting.ts
35+
FN:1,sortReport
36+
FNF:1
37+
FNH:0
38+
FNDA:0,sortReport
39+
DA:1,0
40+
DA:2,0
41+
DA:3,0
42+
DA:4,0
43+
DA:5,0
44+
LF:5
45+
LH:0
46+
BRDA:7,1,0,0
47+
BRDA:7,2,1,0
48+
BRF:2
49+
BRH:0
50+
end_of_record
51+
TN:
52+
SF:src\lib\fully-covered\scoring.ts
53+
FN:2,scoreReport
54+
FN:8,calculateScore
55+
FNF:2
56+
FNH:2
57+
FNDA:3,scoreReport
58+
FNDA:5,calculateScore
59+
DA:1,1
60+
DA:2,1
61+
DA:3,1
62+
DA:4,1
63+
DA:5,1
64+
DA:6,1
65+
DA:7,1
66+
DA:8,1
67+
DA:9,1
68+
DA:10,1
69+
LF:10
70+
LH:10
71+
BRDA:1,0,0,5
72+
BRDA:2,1,0,1
73+
BRDA:2,2,1,4
74+
BRDA:2,3,2,3
75+
BRDA:6,4,0,4
76+
BRF:5
77+
BRH:5
78+
end_of_record

0 commit comments

Comments
 (0)