| 179 | } |
| 180 | |
| 181 | function formatPluginInit( |
| 182 | options: CoverageOptions, |
| 183 | lcovConfigured: boolean, |
| 184 | ): string[] { |
| 185 | const { reportPath, testCommand, types, continueOnFail } = options; |
| 186 | |
| 187 | const hasCustomTypes = |
| 188 | types.length > 0 && types.length < ALL_COVERAGE_TYPES.length; |
| 189 | |
| 190 | const body = [ |
| 191 | `reports: [${singleQuote(reportPath)}],`, |
| 192 | testCommand |
| 193 | ? `coverageToolCommand: { command: ${singleQuote(testCommand)} },` |
| 194 | : '', |
| 195 | hasCustomTypes |
| 196 | ? `coverageTypes: [${types.map(singleQuote).join(', ')}],` |
| 197 | : '', |
| 198 | continueOnFail ? '' : 'continueOnCommandFail: false,', |
| 199 | ].filter(Boolean); |
| 200 | |
| 201 | const init = [ |
| 202 | 'await coveragePlugin({', |
| 203 | ...body.map(line => ` ${line}`), |
| 204 | '}),', |
| 205 | ]; |
| 206 | return lcovConfigured ? init : [LCOV_COMMENT, ...init]; |
| 207 | } |
| 208 | |
| 209 | async function isRecommended(targetDir: string): Promise<boolean> { |
| 210 | return (await detectFramework(targetDir)) !== 'other'; |