( config: FinalCoveragePluginConfig, )
| 10 | import { lcovResultsToAuditOutputs } from './lcov/lcov-runner.js'; |
| 11 | |
| 12 | export function createRunnerFunction( |
| 13 | config: FinalCoveragePluginConfig, |
| 14 | ): RunnerFunction { |
| 15 | return async () => { |
| 16 | const { |
| 17 | reports, |
| 18 | coverageToolCommand, |
| 19 | continueOnCommandFail, |
| 20 | coverageTypes, |
| 21 | } = config; |
| 22 | |
| 23 | // Run coverage tool if provided |
| 24 | if (coverageToolCommand == null) { |
| 25 | logger.info( |
| 26 | 'No test command provided, assuming coverage has already been collected', |
| 27 | ); |
| 28 | } else { |
| 29 | logger.info('Executing test command to collect coverage ...'); |
| 30 | const { command, args } = coverageToolCommand; |
| 31 | try { |
| 32 | await executeProcess({ command, args }); |
| 33 | } catch { |
| 34 | if (!continueOnCommandFail) { |
| 35 | throw new Error( |
| 36 | 'Running coverage tool failed. Make sure all your tests are passing.', |
| 37 | ); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // Calculate coverage from LCOV results |
| 43 | const auditOutputs = await lcovResultsToAuditOutputs( |
| 44 | reports, |
| 45 | coverageTypes, |
| 46 | ); |
| 47 | |
| 48 | logAuditOutputs(auditOutputs); |
| 49 | |
| 50 | return auditOutputs; |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | function logAuditOutputs(auditOutputs: AuditOutputs): void { |
| 55 | logger.info( |
nothing calls this directly
no test coverage detected