-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcoverage-plugin.ts
More file actions
80 lines (74 loc) · 2.17 KB
/
coverage-plugin.ts
File metadata and controls
80 lines (74 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { createRequire } from 'node:module';
import {
type Audit,
type Group,
type PluginConfig,
validate,
} from '@code-pushup/models';
import { capitalize } from '@code-pushup/utils';
import {
type CoveragePluginConfig,
type CoverageType,
coveragePluginConfigSchema,
} from './config.js';
import { createRunnerFunction } from './runner/runner.js';
import { coverageDescription, coverageTypeWeightMapper } from './utils.js';
/**
* Instantiates Code PushUp code coverage plugin for core config.
*
* @example
* import coveragePlugin from '@code-pushup/coverage-plugin'
*
* export default {
* // ... core config ...
* plugins: [
* // ... other plugins ...
* await coveragePlugin({
* reports: [{ resultsPath: 'coverage/cli/lcov.info', pathToProject: 'packages/cli' }]
* })
* ]
* }
*
* @returns Plugin configuration.
*/
export async function coveragePlugin(
config: CoveragePluginConfig,
): Promise<PluginConfig> {
const coverageConfig = validate(coveragePluginConfigSchema, config);
const audits = coverageConfig.coverageTypes.map(
(type): Audit => ({
slug: `${type}-coverage`,
title: `${capitalize(type)} coverage`,
description: coverageDescription[type],
}),
);
const group: Group = {
slug: 'coverage',
title: 'Code coverage metrics',
description: 'Group containing all defined coverage types as audits.',
refs: audits.map(audit => ({
...audit,
weight:
coverageTypeWeightMapper[
audit.slug.slice(0, audit.slug.indexOf('-')) as CoverageType
],
})),
};
const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');
const scoreTargets = coverageConfig.scoreTargets;
return {
slug: 'coverage',
title: 'Code coverage',
icon: 'folder-coverage-open',
description: 'Official Code PushUp code coverage plugin.',
docsUrl: 'https://www.npmjs.com/package/@code-pushup/coverage-plugin/',
packageName: packageJson.name,
version: packageJson.version,
audits,
groups: [group],
runner: createRunnerFunction(coverageConfig),
...(scoreTargets && { scoreTargets }),
};
}