Skip to content

Commit

Permalink
docs(plugin-coverage): improve audit descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlacenka committed Feb 13, 2024
1 parent 8cddfcd commit e05a56e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports[`CLI collect > should run Code coverage plugin and create report.json 1`
{
"audits": [
{
"description": "Branch coverage percentage on the project.",
"description": "Measures how many branches were executed after conditional statements in at least one test.",
"details": {
"issues": [
{
Expand Down Expand Up @@ -85,7 +85,7 @@ exports[`CLI collect > should run Code coverage plugin and create report.json 1`
"value": 76,
},
{
"description": "Function coverage percentage on the project.",
"description": "Measures how many functions were called in at least one test.",
"details": {
"issues": [
{
Expand Down Expand Up @@ -117,7 +117,7 @@ exports[`CLI collect > should run Code coverage plugin and create report.json 1`
"value": 60,
},
{
"description": "Line coverage percentage on the project.",
"description": "Measures how many lines of code were executed in at least one test.",
"details": {
"issues": [
{
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-coverage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Measured coverage types are mapped to Code PushUp audits in the following way

Code coverage is a metric that indicates what percentage of source code is executed by unit tests. It can give insights into test effectiveness and uncover parts of source code that would otherwise go untested.

- Statement coverage: Measures how many statements are executed in at least one test.
- Line coverage: Measures how many lines are executed in at least one test. Unlike statement coverage, any partially executed line counts towards line coverage.
- Condition coverage: Measures all condition values (`true`/`false`) evaluated for a conditional statement in at least one test.
- Branch coverage: Measures how many branches are executed as a result of conditional statements (`if`/`else` and other) in at least one test. In case of short-circuit logic, only executed paths are counted in. Unlike condition coverage, it does not ensure all combinations of condition values are tested.
- Function coverage: Measures how many functions are called in at least one test. Argument values, usage of optional arguments or default values is irrelevant for this metric.

> [!IMPORTANT]
> Please note that code coverage is not the same as test coverage. Test coverage measures the amount of acceptance criteria covered by tests and is hard to formally verify. This means that code coverage cannot guarantee that the designed software caters to the business requirements.
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-coverage/src/lib/coverage-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { capitalize, pluginWorkDir } from '@code-pushup/utils';
import { name, version } from '../../package.json';
import { CoveragePluginConfig, coveragePluginConfigSchema } from './config';
import { lcovResultsToAuditOutputs } from './runner/lcov/runner';
import { applyMaxScoreAboveThreshold } from './utils';
import { applyMaxScoreAboveThreshold, coverageDescription } from './utils';

export const RUNNER_OUTPUT_PATH = join(
pluginWorkDir('coverage'),
Expand Down Expand Up @@ -43,7 +43,7 @@ export function coveragePlugin(config: CoveragePluginConfig): PluginConfig {
(type): Audit => ({
slug: `${type}-coverage`,
title: `${capitalize(type)} coverage`,
description: `${capitalize(type)} coverage percentage on the project.`,
description: coverageDescription[type],
}),
);

Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-coverage/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import type { AuditOutputs } from '@code-pushup/models';
import { CoverageType } from './config';

export const coverageDescription: Record<CoverageType, string> = {
branch:
'Measures how many branches were executed after conditional statements in at least one test.',
line: 'Measures how many lines of code were executed in at least one test.',
function: 'Measures how many functions were called in at least one test.',
};

/**
* Since more code coverage does not necessarily mean better score, this optional override allows for defining custom coverage goals.
Expand Down

0 comments on commit e05a56e

Please sign in to comment.