@code-pushup/coverage-plugin 0.16.7 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -15
- package/bin.js +875 -0
- package/index.js +134 -214
- package/package.json +10 -1
- package/src/bin.d.ts +1 -0
- package/src/index.d.ts +1 -0
- package/src/lib/config.d.ts +3 -2
- package/src/lib/coverage-plugin.d.ts +1 -2
- package/src/lib/nx/coverage-paths.d.ts +6 -0
- package/src/lib/runner/constants.d.ts +3 -0
- package/src/lib/runner/index.d.ts +4 -0
- package/src/lib/runner/lcov/lcov-runner.d.ts +9 -0
- package/src/lib/utils.d.ts +3 -0
- package/src/lib/runner/lcov/runner.d.ts +0 -9
package/README.md
CHANGED
|
@@ -10,6 +10,9 @@ Measured coverage types are mapped to Code PushUp audits in the following way
|
|
|
10
10
|
- the score is value converted to 0-1 range
|
|
11
11
|
- missing coverage is mapped to issues in the audit details (uncalled functions, uncovered branches or lines)
|
|
12
12
|
|
|
13
|
+
> [!IMPORTANT]
|
|
14
|
+
> In order to successfully run your coverage tool and gather coverage results directly within the plugin, all your tests need to pass!
|
|
15
|
+
|
|
13
16
|
## Getting started
|
|
14
17
|
|
|
15
18
|
1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file.
|
|
@@ -43,7 +46,7 @@ Measured coverage types are mapped to Code PushUp audits in the following way
|
|
|
43
46
|
};
|
|
44
47
|
```
|
|
45
48
|
|
|
46
|
-
4. (Optional) Reference audits which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups).
|
|
49
|
+
4. (Optional) Reference individual audits or the provided plugin group which you wish to include in custom categories (use `npx code-pushup print-config` to list audits and groups).
|
|
47
50
|
|
|
48
51
|
💡 Assign weights based on what influence each coverage type should have on the overall category score (assign weight 0 to only include as extra info, without influencing category score).
|
|
49
52
|
|
|
@@ -56,21 +59,9 @@ Measured coverage types are mapped to Code PushUp audits in the following way
|
|
|
56
59
|
title: 'Code coverage',
|
|
57
60
|
refs: [
|
|
58
61
|
{
|
|
59
|
-
type: '
|
|
60
|
-
plugin: 'coverage',
|
|
61
|
-
slug: 'function-coverage',
|
|
62
|
-
weight: 2,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
type: 'audit',
|
|
62
|
+
type: 'group',
|
|
66
63
|
plugin: 'coverage',
|
|
67
|
-
slug: '
|
|
68
|
-
weight: 1,
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
type: 'audit',
|
|
72
|
-
plugin: 'coverage',
|
|
73
|
-
slug: 'line-coverage',
|
|
64
|
+
slug: 'coverage',
|
|
74
65
|
weight: 1,
|
|
75
66
|
},
|
|
76
67
|
// ...
|
|
@@ -87,6 +78,12 @@ Measured coverage types are mapped to Code PushUp audits in the following way
|
|
|
87
78
|
|
|
88
79
|
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.
|
|
89
80
|
|
|
81
|
+
- **Statement coverage**: Measures how many statements are executed in at least one test.
|
|
82
|
+
- **Line coverage**: Measures how many lines are executed in at least one test. Unlike statement coverage, any partially executed line counts towards line coverage.
|
|
83
|
+
- **Condition coverage**: Measures all condition values (`true`/`false`) evaluated for a conditional statement in at least one test.
|
|
84
|
+
- **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.
|
|
85
|
+
- **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.
|
|
86
|
+
|
|
90
87
|
> [!IMPORTANT]
|
|
91
88
|
> 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.
|
|
92
89
|
|
|
@@ -123,9 +120,62 @@ The plugin accepts the following parameters:
|
|
|
123
120
|
|
|
124
121
|
- `coverageTypes`: An array of types of coverage that you wish to track. Supported values: `function`, `branch`, `line`. Defaults to all available types.
|
|
125
122
|
- `reports`: Array of information about files with code coverage results - paths to results, path to project root the results belong to. LCOV format is supported for now.
|
|
123
|
+
- If you have an Nx monorepo, you can adjust our helper function `getNxCoveragePaths` to get the path information automatically.
|
|
126
124
|
- (optional) `coverageToolCommand`: If you wish to run your coverage tool to generate the results first, you may define it here.
|
|
127
125
|
- (optional) `perfectScoreThreshold`: If your coverage goal is not 100%, you may define it here in range 0-1. Any score above the defined threshold will be given the perfect score. The value will stay unaffected.
|
|
128
126
|
|
|
127
|
+
### Audits and group
|
|
128
|
+
|
|
129
|
+
This plugin provides a group for convenient declaration in your config. When defined this way, all measured coverage type audits have the same weight.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
// ...
|
|
133
|
+
categories: [
|
|
134
|
+
{
|
|
135
|
+
slug: 'code-coverage',
|
|
136
|
+
title: 'Code coverage',
|
|
137
|
+
refs: [
|
|
138
|
+
{
|
|
139
|
+
type: 'group',
|
|
140
|
+
plugin: 'coverage',
|
|
141
|
+
slug: 'coverage',
|
|
142
|
+
weight: 1,
|
|
143
|
+
},
|
|
144
|
+
// ...
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
// ...
|
|
148
|
+
],
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Each coverage type still has its own audit. So when you want to include a subset of coverage types or assign different weights to them, you can do so in the following way:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
// ...
|
|
155
|
+
categories: [
|
|
156
|
+
{
|
|
157
|
+
slug: 'code-coverage',
|
|
158
|
+
title: 'Code coverage',
|
|
159
|
+
refs: [
|
|
160
|
+
{
|
|
161
|
+
type: 'audit',
|
|
162
|
+
plugin: 'coverage',
|
|
163
|
+
slug: 'function-coverage',
|
|
164
|
+
weight: 2,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
type: 'audit',
|
|
168
|
+
plugin: 'coverage',
|
|
169
|
+
slug: 'branch-coverage',
|
|
170
|
+
weight: 1,
|
|
171
|
+
},
|
|
172
|
+
// ...
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
// ...
|
|
176
|
+
],
|
|
177
|
+
```
|
|
178
|
+
|
|
129
179
|
### Audit output
|
|
130
180
|
|
|
131
181
|
An audit is an aggregation of all results for one coverage type passed to the plugin.
|
|
@@ -157,3 +207,14 @@ For instance, the following can be an audit output for line coverage.
|
|
|
157
207
|
}
|
|
158
208
|
}
|
|
159
209
|
```
|
|
210
|
+
|
|
211
|
+
### Providing coverage results in Nx monorepo
|
|
212
|
+
|
|
213
|
+
As a part of the plugin, there is a `getNxCoveragePaths` helper for setting up paths to coverage results if you are using Nx. The helper accepts all relevant targets (e.g. `test` or `unit-test`) and searches for a coverage path option.
|
|
214
|
+
Jest and Vitest configuration options are currently supported:
|
|
215
|
+
|
|
216
|
+
- For `@nx/jest` executor it looks for the `coverageDirectory` option.
|
|
217
|
+
- For `@nx/vite` executor it looks for the `reportsDirectory` option.
|
|
218
|
+
|
|
219
|
+
> [!IMPORTANT]
|
|
220
|
+
> Please note that you need to set up the coverage directory option in your `project.json` target options. Test configuration files are not searched.
|