e2ed
Version:
E2E testing framework over Playwright
50 lines (49 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderJsonData = void 0;
const internal_1 = require("../../../constants/internal");
const client_1 = require("../client");
const filterErrors = (fullTestRuns) => {
const errors = [];
const rest = [];
for (const fullTestRun of fullTestRuns) {
if (internal_1.FAILED_TEST_RUN_STATUSES.includes(fullTestRun.status)) {
errors.push(fullTestRun);
}
else {
rest.push(fullTestRun);
}
}
return [errors, rest];
};
/**
* Renders `<script>` tags with JSON presentation of report data.
* In first tag renders the errors of the last retry, then the entire last retry,
* then all the remaining errors, tnen general client data, and then all the remaining data.
* @internal
*/
const renderJsonData = (reportData) => {
const { apiStatistics, retries } = reportData;
const reportClientData = { apiStatistics };
const fullTestRunsNotFromLastRetry = [];
const lastRetry = retries.at(-1);
for (let index = 0; index < retries.length - 1; index += 1) {
fullTestRunsNotFromLastRetry.push(...(retries[index]?.fullTestRuns ?? []));
}
const [lastRetryErrors, lastRetryRest] = filterErrors(lastRetry?.fullTestRuns ?? []);
const [restErrors, rest] = filterErrors(fullTestRunsNotFromLastRetry);
const parts = [
lastRetryErrors,
lastRetryRest,
restErrors,
reportClientData,
rest,
].filter((part) => !('length' in part) || part.length > 0);
const scripts = parts.map((fullTestRuns) => {
const json = JSON.stringify(fullTestRuns);
const sanitizedJson = (0, client_1.sanitizeJson)(json);
return (0, client_1.createSafeHtmlWithoutSanitize) `<script class="e2edJsonReportData" type="plain/text">${sanitizedJson}</script>`;
});
return (0, client_1.createSafeHtmlWithoutSanitize) `${scripts.join('')}`;
};
exports.renderJsonData = renderJsonData;