Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions report-app/report-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
FetchedLocalReports,
fetchReportsFromDisk,
} from '../runner/reporting/report-local-disk';
import { RunInfo } from '../runner/shared-interfaces';
import { convertV2ReportToV3Report } from '../runner/reporting/migrations/v2_to_v3';

const app = express();
const reportsLoader = await getReportLoader();
Expand Down Expand Up @@ -39,14 +41,17 @@ app.get('/api/reports', async (_, res) => {
app.get('/api/reports/:id', async (req, res) => {
const id = req.params.id;
const localData = await resolveLocalData(options.reportsRoot);
let result: { group: string }[] | null = null;
let result: RunInfo[] | null = null;

if (localData.has(id)) {
result = [localData.get(id)!.run];
} else {
result = await reportsLoader.getGroupedReports(id);
}

// Convert potential older v2 reports.
result = result.map((r) => convertV2ReportToV3Report(r));

res.json(result);
});

Expand Down Expand Up @@ -79,7 +84,7 @@ if (isMainModule(import.meta.url)) {
export const reqHandler = createNodeRequestHandler(app);

interface ReportLoader {
getGroupedReports: (groupId: string) => Promise<{ group: string }[]>;
getGroupedReports: (groupId: string) => Promise<RunInfo[]>;
getGroupsList: () => Promise<{ id: string }[]>;
configureEndpoints?: (expressApp: typeof app) => Promise<void>;
}
Expand Down
48 changes: 48 additions & 0 deletions runner/reporting/migrations/v2_to_v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Migrates a v2 report to a v3 report.
* See: https://github.com/angular/web-codegen-scorer/commit/41ada541481a10c99de055ab6bb1c19b06a25b88.
*/
export function convertV2ReportToV3Report(doc: any) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth starting to keep the v2 interfaces?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be a bit concerned that things will become hard to maintain if we keep making changes to the report shape.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, we can always trim these when there will be too much and make a clear breaking change. Plus we don't necessarily anticipate many more report structure changes.

if (doc.version === 3) {
return doc;
}

const migrateFromBuildResultToSplit = (origBuildResult: any) => {
const buildResult = {
status: origBuildResult.status,
message: origBuildResult.message,
errorType: origBuildResult.errorType,
safetyWebReportJson: origBuildResult.safetyWebReportJson,
missingDependency: origBuildResult.missingDependency,
};
const serveTestingResult = {
errorMessage: undefined,
screenshotPngUrl: origBuildResult.screenshotPngUrl,
runtimeErrors: origBuildResult.runtimeErrors,
userJourneyAgentOutput: origBuildResult.userJourneyAgentOutput,
cspViolations: origBuildResult.cspViolations,
axeViolations: origBuildResult.axeViolations,
};

return { buildResult, serveTestingResult };
};

for (const result of doc.results) {
const finalAttemptSplit = migrateFromBuildResultToSplit(result.build);
result.finalAttempt = {
buildResult: finalAttemptSplit.buildResult,
serveTestingResult: finalAttemptSplit.serveTestingResult,
};
delete result.build;

for (const attempt of result.attemptDetails) {
const attemptSplit = migrateFromBuildResultToSplit(attempt.buildResult);
attempt.buildResult = attemptSplit.buildResult;
attempt.serveTestingResult = attemptSplit.serveTestingResult;
}
}

doc.version = 3;

return doc;
}
Loading