UNPKG

eslint-rule-benchmark

Version:

Benchmark ESLint rules with detailed performance metrics for CI and plugin development

64 lines (63 loc) 2.08 kB
import fs from 'node:fs/promises' import path from 'node:path' import { publishGithubComment } from '../integrations/publish-github-comment.js' import { isGithubPullRequest } from '../integrations/is-github-pull-request.js' import { createReporter } from './create-reporter.js' async function runReporters( allTestSpecResults, userConfig, reporterOptionsFromCli, ) { if (reporterOptionsFromCli.length === 0) { console.warn('No reporters configured. Skipping report generation.') return } await Promise.all( reporterOptionsFromCli.map(async reporterOpt => { try { let reportContent = await createReporter( allTestSpecResults, userConfig, reporterOpt.format, ) if (reporterOpt.outputPath) { let resolvedOutputPath = path.resolve(reporterOpt.outputPath) await fs.mkdir(path.dirname(resolvedOutputPath), { recursive: true }) await fs.writeFile(resolvedOutputPath, reportContent, 'utf8') console.info( `Report in "${reporterOpt.format}" format saved to: ${resolvedOutputPath}`, ) } else if (reporterOpt.format === 'console') { console.info(reportContent) } else { console.warn( `Report content for format "${reporterOpt.format}" (no outputPath specified): `, ) console.warn(reportContent) } } catch (error) { let errorValue = error console.error( `Error generating report for format "${reporterOpt.format}": ${errorValue.message}`, errorValue.stack, ) } }), ) if (isGithubPullRequest()) { try { let markdownReport = await createReporter( allTestSpecResults, userConfig, 'markdown', ) await publishGithubComment(markdownReport) console.info('GitHub comment published successfully.') } catch (error) { let errorValue = error console.error(`Error publishing GitHub comment: ${errorValue.message}`) } } } export { runReporters }