( args: CompareReportsArgs, )
| 207 | } |
| 208 | |
| 209 | export 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 | |
| 261 | export async function saveDiffFiles( |
| 262 | args: CompareReportsArgs, |
no test coverage detected