(
config: {
persist: Required<PersistConfig>;
upload?: UploadConfig;
},
options?: CompareOptions,
)
| 34 | }; |
| 35 | |
| 36 | export async function compareReportFiles( |
| 37 | config: { |
| 38 | persist: Required<PersistConfig>; |
| 39 | upload?: UploadConfig; |
| 40 | }, |
| 41 | options?: CompareOptions, |
| 42 | ): Promise<string[]> { |
| 43 | const { outputDir, filename, format } = config.persist; |
| 44 | |
| 45 | const defaultInputPath = (suffix: keyof Diff<string>) => |
| 46 | createReportPath({ outputDir, filename, format: 'json', suffix }); |
| 47 | |
| 48 | const [reportBefore, reportAfter] = await Promise.all([ |
| 49 | readJsonFile(options?.before ?? defaultInputPath('before')), |
| 50 | readJsonFile(options?.after ?? defaultInputPath('after')), |
| 51 | ]); |
| 52 | const reports: Diff<Report> = { |
| 53 | before: validate(reportSchema, reportBefore), |
| 54 | after: validate(reportSchema, reportAfter), |
| 55 | }; |
| 56 | |
| 57 | const diff = compareReports(reports); |
| 58 | |
| 59 | const label = options?.label ?? getLabelFromReports(reports); |
| 60 | const portalUrl = |
| 61 | config.upload && |
| 62 | diff.commits && |
| 63 | (await fetchPortalComparisonLink(config.upload, diff.commits)); |
| 64 | |
| 65 | const diffWithLinks: ReportsDiff = |
| 66 | label || portalUrl |
| 67 | ? { ...diff, ...(label && { label }), ...(portalUrl && { portalUrl }) } |
| 68 | : diff; |
| 69 | |
| 70 | return Promise.all( |
| 71 | format.map(async fmt => { |
| 72 | const outputPath = createReportPath({ |
| 73 | outputDir, |
| 74 | filename, |
| 75 | format: fmt, |
| 76 | suffix: 'diff', |
| 77 | }); |
| 78 | const content = reportsDiffToFileContent(diffWithLinks, fmt); |
| 79 | await ensureDirectoryExists(outputDir); |
| 80 | await writeFile(outputPath, content); |
| 81 | return outputPath; |
| 82 | }), |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | export function compareReports(reports: Diff<Report>): ReportsDiff { |
| 87 | const start = performance.now(); |
no test coverage detected