tdpw
Version:
CLI tool for uploading Playwright test reports to TestDino platform with TestDino storage support
51 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parsePlaywrightJson = parsePlaywrightJson;
const zod_1 = require("zod");
const fs_1 = require("../utils/fs");
const types_1 = require("../types");
/**
* Zod schema for validating essential parts of a Playwright JSON report
*/
const PlaywrightReportSchema = zod_1.z.object({
config: zod_1.z.any(),
suites: zod_1.z.array(zod_1.z.any()),
stats: zod_1.z.object({
startTime: zod_1.z.string(),
duration: zod_1.z.number(),
expected: zod_1.z.number(),
skipped: zod_1.z.number(),
unexpected: zod_1.z.number(),
flaky: zod_1.z.number(),
}),
errors: zod_1.z.array(zod_1.z.any()).optional(),
metadata: zod_1.z.any().optional(),
});
/**
* Read, parse, and validate a Playwright JSON report from disk.
* @param jsonPath Absolute path to the Playwright JSON report
* @throws ValidationError if reading, parsing, or validation fails
*/
async function parsePlaywrightJson(jsonPath) {
let raw;
try {
raw = await (0, fs_1.readFile)(jsonPath);
}
catch (error) {
throw new types_1.ValidationError(`Failed to read JSON report at "${jsonPath}": ${error.message}`);
}
let parsed;
try {
parsed = JSON.parse(raw);
}
catch (error) {
throw new types_1.ValidationError(`Invalid JSON format in report: ${error.message}`);
}
const result = PlaywrightReportSchema.safeParse(parsed);
if (!result.success) {
const issues = result.error.issues.map(issue => `${issue.path.join('.')}: ${issue.message}`);
throw new types_1.ValidationError(`Playwright report validation failed: ${issues.join(', ')}`);
}
return result.data;
}
//# sourceMappingURL=parser.js.map