Files
callstack__agent-device/test/integration/web-e2e/coverage-report.ts
Michał Pierzchała b4331815e2 test: add web platform command coverage manifest (#1902)
* test: add web platform command coverage manifest

* fix: preserve web coverage report on cleanup failure
2026-08-20 15:59:50 +02:00

64 lines
1.5 KiB
TypeScript

import fs from 'node:fs';
import path from 'node:path';
import {
WEB_PLATFORM_COVERAGE_CLASSIFICATION_SUMMARY,
liveCommandsForWebSmoke,
} from './coverage-manifest.ts';
export type WebSmokeStep = {
command: string;
status: number;
};
export async function runCleanupWithCoverageReport(
artifactDir: string,
steps: readonly WebSmokeStep[],
cleanup: () => Promise<void>,
): Promise<void> {
let cleanupFailed = false;
let cleanupError: unknown;
let reportFailed = false;
let reportError: unknown;
try {
try {
await cleanup();
} catch (error) {
cleanupFailed = true;
cleanupError = error;
}
} finally {
try {
writeCoverageReport(artifactDir, steps);
} catch (error) {
reportFailed = true;
reportError = error;
}
}
if (cleanupFailed && reportFailed) {
throw new AggregateError(
[cleanupError, reportError],
'web smoke cleanup and coverage reporting failed',
);
}
if (cleanupFailed) throw cleanupError;
if (reportFailed) throw reportError;
}
export function writeCoverageReport(artifactDir: string, steps: readonly WebSmokeStep[]): string {
const reportPath = path.join(artifactDir, 'coverage-report.json');
fs.writeFileSync(
reportPath,
JSON.stringify(
{
classificationSummary: WEB_PLATFORM_COVERAGE_CLASSIFICATION_SUMMARY,
liveCommands: liveCommandsForWebSmoke(),
steps,
},
null,
2,
),
);
return reportPath;
}