MCPcopy Create free account
hub / github.com/code-pushup/cli / compareReportFiles

Function compareReportFiles

packages/core/src/lib/compare.ts:36–84  ·  view source on GitHub ↗
(
  config: {
    persist: Required<PersistConfig>;
    upload?: UploadConfig;
  },
  options?: CompareOptions,
)

Source from the content-addressed store, hash-verified

34};
35
36export 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
86export function compareReports(reports: Diff<Report>): ReportsDiff {
87 const start = performance.now();

Callers 2

Calls 10

readJsonFileFunction · 0.90
validateFunction · 0.90
createReportPathFunction · 0.90
ensureDirectoryExistsFunction · 0.90
defaultInputPathFunction · 0.85
getLabelFromReportsFunction · 0.85
reportsDiffToFileContentFunction · 0.85
writeFileFunction · 0.85
compareReportsFunction · 0.70

Tested by

no test coverage detected