( config: CoveragePluginConfig, )
| 35 | * @returns Plugin configuration. |
| 36 | */ |
| 37 | export async function coveragePlugin( |
| 38 | config: CoveragePluginConfig, |
| 39 | ): Promise<PluginConfig> { |
| 40 | const coverageConfig = validate(coveragePluginConfigSchema, config); |
| 41 | |
| 42 | const audits = coverageConfig.coverageTypes.map( |
| 43 | (type): Audit => ({ |
| 44 | slug: typeToAuditSlug(type), |
| 45 | title: typeToAuditTitle(type), |
| 46 | description: coverageDescription[type], |
| 47 | }), |
| 48 | ); |
| 49 | |
| 50 | const group: Group = { |
| 51 | slug: 'coverage', |
| 52 | title: 'Code coverage metrics', |
| 53 | description: 'Group containing all defined coverage types as audits.', |
| 54 | refs: audits.map(audit => ({ |
| 55 | ...audit, |
| 56 | weight: |
| 57 | coverageTypeWeightMapper[ |
| 58 | audit.slug.slice(0, audit.slug.indexOf('-')) as CoverageType |
| 59 | ], |
| 60 | })), |
| 61 | }; |
| 62 | |
| 63 | logger.info( |
| 64 | formatMetaLog( |
| 65 | `Created ${pluralizeToken('audit', audits.length)} (${coverageConfig.coverageTypes.join('/')} coverage) and 1 group`, |
| 66 | ), |
| 67 | ); |
| 68 | |
| 69 | const packageJson = createRequire(import.meta.url)( |
| 70 | '../../package.json', |
| 71 | ) as typeof import('../../package.json'); |
| 72 | |
| 73 | const scoreTargets = coverageConfig.scoreTargets; |
| 74 | |
| 75 | return { |
| 76 | slug: COVERAGE_PLUGIN_SLUG, |
| 77 | title: COVERAGE_PLUGIN_TITLE, |
| 78 | icon: 'folder-coverage-open', |
| 79 | description: 'Official Code PushUp code coverage plugin.', |
| 80 | docsUrl: 'https://www.npmjs.com/package/@code-pushup/coverage-plugin/', |
| 81 | packageName: packageJson.name, |
| 82 | version: packageJson.version, |
| 83 | audits, |
| 84 | groups: [group], |
| 85 | runner: createRunnerFunction(coverageConfig), |
| 86 | ...(scoreTargets && { scoreTargets }), |
| 87 | }; |
| 88 | } |
no test coverage detected