Skip to content

feat(plugin-coverage): introduce coverage plugin #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 5, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
🧩 nx-plugin: packages/nx-plugin/**
🧩 eslint-plugin: packages/plugin-eslint/**
🧩 lighthouse-plugin: packages/plugin-lighthouse/**
🧩 coverage-plugin: packages/plugin-coverage/**
🧩 utils: packages/utils/**

🔬 testing:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ jobs:
cache: npm
- name: Install dependencies
run: npm ci
- name: Collect unit test coverage
run: npx nx run-many -t unit-test --coverage
- name: Collect Code PushUp report
run: npx nx run-collect
- name: Upload Code PushUp report to portal
Expand Down
54 changes: 53 additions & 1 deletion code-pushup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
packageJsonPerformanceGroupRef,
packageJsonPlugin,
} from './dist/examples/plugins';
import coveragePlugin from './dist/packages/plugin-coverage';
import eslintPlugin, {
eslintConfigFromNxProjects,
} from './dist/packages/plugin-eslint';
Expand Down Expand Up @@ -44,7 +45,34 @@ const config: CoreConfig = {

plugins: [
await eslintPlugin(await eslintConfigFromNxProjects()),

coveragePlugin({
reports: [
{
resultsPath: 'coverage/cli/unit-tests/lcov.info',
pathToProject: 'packages/cli',
},
{
resultsPath: 'coverage/core/unit-tests/lcov.info',
pathToProject: 'packages/core',
},
{
resultsPath: 'coverage/models/unit-tests/lcov.info',
pathToProject: 'packages/models',
},
{
resultsPath: 'coverage/utils/unit-tests/lcov.info',
pathToProject: 'packages/utils',
},
{
resultsPath: 'coverage/plugin-eslint/unit-tests/lcov.info',
pathToProject: 'packages/plugin-eslint',
},
{
resultsPath: 'coverage/plugin-coverage/unit-tests/lcov.info',
pathToProject: 'packages/plugin-coverage',
},
],
}),
fileSizePlugin({
directory: './dist/examples/react-todos-app',
pattern: /\.js$/,
Expand All @@ -71,6 +99,30 @@ const config: CoreConfig = {
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
{
slug: 'code-coverage',
title: 'Code coverage',
refs: [
{
type: 'audit',
plugin: 'coverage',
slug: 'function-coverage',
weight: 1,
},
{
type: 'audit',
plugin: 'coverage',
slug: 'branch-coverage',
weight: 1,
},
{
type: 'audit',
plugin: 'coverage',
slug: 'line-coverage',
weight: 1,
},
],
},
{
slug: 'custom-checks',
title: 'Custom checks',
Expand Down
2 changes: 1 addition & 1 deletion e2e/cli-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "code-pushup.config.ts"],
"ignorePatterns": ["!**/*", "code-pushup.config*.ts"],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
Expand Down
49 changes: 49 additions & 0 deletions e2e/cli-e2e/mocks/fixtures/code-pushup.config.coverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { join } from 'node:path';
import coveragePlugin from '@code-pushup/coverage-plugin';
import { CoreConfig } from '@code-pushup/models';

export default {
upload: {
organization: 'code-pushup',
project: 'cli-ts',
apiKey: 'e2e-api-key',
server: 'https://e2e.com/api',
},
categories: [
{
slug: 'code-coverage',
title: 'Code coverage',
refs: [
{
type: 'audit',
plugin: 'coverage',
slug: 'function-coverage',
weight: 1,
},
{
type: 'audit',
plugin: 'coverage',
slug: 'branch-coverage',
weight: 1,
},
{
type: 'audit',
plugin: 'coverage',
slug: 'line-coverage',
weight: 1,
},
],
},
],
plugins: [
coveragePlugin({
coverageTypes: ['branch', 'function', 'line'],
reports: [
{
resultsPath: join('e2e', 'cli-e2e', 'mocks', 'fixtures', 'lcov.info'),
pathToProject: join('packages', 'cli'),
},
],
}),
],
} satisfies CoreConfig;
78 changes: 78 additions & 0 deletions e2e/cli-e2e/mocks/fixtures/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
TN:
SF:src\lib\partly-covered\utils.ts
FN:2,formatReportScore
FN:6,calcDuration
FNF:2
FNH:1
FNDA:0,formatReportScore
FNDA:6,calcDuration
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,0
DA:8,0
DA:9,0
DA:10,1
LF:10
LH:7
BRDA:1,0,0,6
BRDA:1,1,0,5
BRDA:2,4,0,1
BRDA:4,5,0,17
BRDA:5,6,0,4
BRDA:6,7,0,13
BRDA:6,10,1,0
BRDA:7,11,0,3
BRDA:10,12,0,12
BRDA:10,13,1,0
BRF:10
BRH:8
end_of_record
SF:src\lib\not-covered\sorting.ts
FN:1,sortReport
FNF:1
FNH:0
FNDA:0,sortReport
DA:1,0
DA:2,0
DA:3,0
DA:4,0
DA:5,0
LF:5
LH:0
BRDA:7,1,0,0
BRDA:7,2,1,0
BRF:2
BRH:0
end_of_record
TN:
SF:src\lib\fully-covered\scoring.ts
FN:2,scoreReport
FN:8,calculateScore
FNF:2
FNH:2
FNDA:3,scoreReport
FNDA:5,calculateScore
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
DA:10,1
LF:10
LH:10
BRDA:1,0,0,5
BRDA:2,1,0,1
BRDA:2,2,1,4
BRDA:2,3,2,3
BRDA:6,4,0,4
BRF:5
BRH:5
end_of_record
1 change: 1 addition & 0 deletions e2e/cli-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"cli",
"plugin-eslint",
"plugin-lighthouse",
"plugin-coverage",
"react-todos-app"
],
"tags": ["scope:core", "scope:plugin", "type:e2e"]
Expand Down
Loading