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

Function prepareReportFilesToCompare

packages/ci/src/lib/run-utils.ts:209–259  ·  view source on GitHub ↗
(
  args: CompareReportsArgs,
)

Source from the content-addressed store, hash-verified

207}
208
209export async function prepareReportFilesToCompare(
210 args: CompareReportsArgs,
211): Promise<Diff<string>> {
212 const { config, project, ctx } = args;
213 const {
214 outputDir = DEFAULT_PERSIST_OUTPUT_DIR,
215 filename = DEFAULT_PERSIST_FILENAME,
216 } = config.persist ?? {};
217 const label = project?.name;
218
219 const originalReports = await Promise.all(
220 [args.currReport, args.prevReport].map(({ files }) =>
221 readJsonFile<Report>(files.json),
222 ),
223 );
224 const labeledReports = label
225 ? originalReports.map(report => ({ ...report, label }))
226 : originalReports;
227
228 const reportPaths = labeledReports.map((report, idx) => {
229 const key: keyof Diff<string> = idx === 0 ? 'after' : 'before';
230 const filePath = createReportPath({
231 outputDir: path.resolve(ctx.directory, outputDir),
232 filename,
233 format: 'json',
234 suffix: key,
235 });
236 return { key, report, filePath };
237 });
238
239 await Promise.all(
240 reportPaths.map(({ filePath, report }) =>
241 writeFile(filePath, JSON.stringify(report, null, 2)),
242 ),
243 );
244
245 logDebug(
246 [
247 'Prepared',
248 project && `"${project.name}" project's`,
249 'report files for comparison',
250 `at ${reportPaths.map(({ filePath }) => filePath).join(' and ')}`,
251 ]
252 .filter(Boolean)
253 .join(' '),
254 );
255
256 return objectFromEntries(
257 reportPaths.map(({ key, filePath }) => [key, filePath]),
258 );
259}
260
261export async function saveDiffFiles(
262 args: CompareReportsArgs,

Callers 1

compareReportsFunction · 0.85

Calls 5

readJsonFileFunction · 0.90
createReportPathFunction · 0.90
objectFromEntriesFunction · 0.90
writeFileFunction · 0.85
logDebugFunction · 0.85

Tested by

no test coverage detected