1
- import { join } from 'node:path' ;
2
- import type {
3
- Audit ,
4
- Group ,
5
- PluginConfig ,
6
- RunnerConfig ,
7
- RunnerFunction ,
8
- } from '@code-pushup/models' ;
9
- import { capitalize , pluginWorkDir } from '@code-pushup/utils' ;
1
+ import { dirname , join } from 'node:path' ;
2
+ import { fileURLToPath } from 'node:url' ;
3
+ import type { Audit , Group , PluginConfig } from '@code-pushup/models' ;
4
+ import { capitalize } from '@code-pushup/utils' ;
10
5
import { name , version } from '../../package.json' ;
11
6
import { CoveragePluginConfig , coveragePluginConfigSchema } from './config' ;
12
- import { lcovResultsToAuditOutputs } from './runner/lcov/runner' ;
13
- import { applyMaxScoreAboveThreshold , coverageDescription } from './utils' ;
14
-
15
- export const RUNNER_OUTPUT_PATH = join (
16
- pluginWorkDir ( 'coverage' ) ,
17
- 'runner-output.json' ,
18
- ) ;
7
+ import { createRunnerConfig } from './runner' ;
8
+ import { coverageDescription } from './utils' ;
19
9
20
10
/**
21
11
* Instantiates Code PushUp code coverage plugin for core config.
@@ -35,11 +25,12 @@ export const RUNNER_OUTPUT_PATH = join(
35
25
*
36
26
* @returns Plugin configuration.
37
27
*/
38
- export function coveragePlugin ( config : CoveragePluginConfig ) : PluginConfig {
39
- const { reports, perfectScoreThreshold, coverageTypes, coverageToolCommand } =
40
- coveragePluginConfigSchema . parse ( config ) ;
28
+ export async function coveragePlugin (
29
+ config : CoveragePluginConfig ,
30
+ ) : Promise < PluginConfig > {
31
+ const coverageConfig = coveragePluginConfigSchema . parse ( config ) ;
41
32
42
- const audits = coverageTypes . map (
33
+ const audits = coverageConfig . coverageTypes . map (
43
34
( type ) : Audit => ( {
44
35
slug : `${ type } -coverage` ,
45
36
title : `${ capitalize ( type ) } coverage` ,
@@ -54,25 +45,10 @@ export function coveragePlugin(config: CoveragePluginConfig): PluginConfig {
54
45
refs : audits . map ( audit => ( { ...audit , weight : 1 } ) ) ,
55
46
} ;
56
47
57
- const getAuditOutputs = async ( ) =>
58
- perfectScoreThreshold
59
- ? applyMaxScoreAboveThreshold (
60
- await lcovResultsToAuditOutputs ( reports , coverageTypes ) ,
61
- perfectScoreThreshold ,
62
- )
63
- : await lcovResultsToAuditOutputs ( reports , coverageTypes ) ;
64
-
65
- // if coverage results are provided, only convert them to AuditOutputs
66
- // if not, run coverage command and then run result conversion
67
- const runner : RunnerConfig | RunnerFunction =
68
- coverageToolCommand == null
69
- ? getAuditOutputs
70
- : {
71
- command : coverageToolCommand . command ,
72
- args : coverageToolCommand . args ,
73
- outputFile : RUNNER_OUTPUT_PATH ,
74
- outputTransform : getAuditOutputs ,
75
- } ;
48
+ const runnerScriptPath = join (
49
+ fileURLToPath ( dirname ( import . meta. url ) ) ,
50
+ 'bin.js' ,
51
+ ) ;
76
52
77
53
return {
78
54
slug : 'coverage' ,
@@ -84,6 +60,6 @@ export function coveragePlugin(config: CoveragePluginConfig): PluginConfig {
84
60
version,
85
61
audits,
86
62
groups : [ group ] ,
87
- runner,
63
+ runner : await createRunnerConfig ( runnerScriptPath , coverageConfig ) ,
88
64
} ;
89
65
}
0 commit comments