@applitools/eyes-playwright
Version:
Applitools Eyes SDK for Playwright
103 lines (102 loc) • 3.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSingleSessionStatus = exports.countTestsByStatus = exports.getStatus = exports.getLastRetryResults = void 0;
const SESSION_STATUS = {
Failed: 'failed',
Passed: 'passed',
Running: 'running',
Unresolved: 'unresolved',
};
const STATUS = {
Aborted: 'aborted',
Default: 'default',
Failed: 'failed',
New: 'new',
Passed: 'passed',
Running: 'running',
Unresolved: 'unresolved',
Unsaved: 'unsaved',
Empty: 'empty',
};
const STATUS_PRIORITY = [
SESSION_STATUS.Running,
SESSION_STATUS.Passed,
SESSION_STATUS.Failed,
SESSION_STATUS.Unresolved,
];
function getLastRetryResults(eyesResults) {
if (eyesResults.length === 0) {
return [];
}
// Find the highest retry number (last retry attempt)
const maxRetry = Math.max(...eyesResults.map(r => { var _a; return (_a = r.playwrightRetry) !== null && _a !== void 0 ? _a : 0; }));
// Return only results from the last retry
return eyesResults.filter(r => { var _a; return ((_a = r.playwrightRetry) !== null && _a !== void 0 ? _a : 0) === maxRetry; });
}
exports.getLastRetryResults = getLastRetryResults;
function getStatus(eyesResults) {
// Use only the last retry's results
const lastRetryResults = getLastRetryResults(eyesResults);
if (lastRetryResults.length === 0) {
// No results at all
return { status: 'empty', statusText: STATUS.Empty, icon: null };
}
// Aggregate result flags using reduce for better functional style
const { maxPriority, isAborted, isNew, isDifferent, isEmpty } = lastRetryResults.reduce((acc, result) => {
const statusPriority = STATUS_PRIORITY.indexOf(result.status.toLowerCase());
return {
maxPriority: Math.max(statusPriority, acc.maxPriority),
isAborted: acc.isAborted || result.isAborted,
isNew: acc.isNew || result.isNew,
isDifferent: acc.isDifferent || result.isDifferent,
isEmpty: acc.isEmpty && result.steps === 0,
};
}, { maxPriority: 0, isAborted: false, isNew: false, isDifferent: false, isEmpty: true });
const priorityIndex = isAborted ? Math.max(2, maxPriority) : maxPriority;
const status = STATUS_PRIORITY[priorityIndex];
const statusText = isAborted
? STATUS.Aborted
: isEmpty
? STATUS.Empty
: status !== SESSION_STATUS.Running && isNew
? STATUS.New
: status;
const icon = isAborted ? null : isNew ? 'new' : isDifferent ? 'different' : 'resolved';
return { status, statusText, icon };
}
exports.getStatus = getStatus;
function countTestsByStatus(eyesTestResult) {
return Object.values(eyesTestResult).reduce((counts, test) => {
counts.total++;
// getStatus() automatically uses only the last retry's results
const status = getStatus(test.eyesResults).status;
// Use type-safe property access with mapped type
if (status === 'passed' || status === 'failed' || status === 'unresolved') {
counts[status]++;
}
return counts;
}, { total: 0, passed: 0, failed: 0, unresolved: 0 });
}
exports.countTestsByStatus = countTestsByStatus;
function getSingleSessionStatus(test) {
let maxPriority = Math.max(STATUS_PRIORITY.indexOf(test.status.toLowerCase()), 0);
let statusText;
let status = STATUS_PRIORITY[maxPriority];
const isEmpty = test.steps === 0;
if (test.isAborted) {
maxPriority = Math.max(2, maxPriority);
status = STATUS_PRIORITY[maxPriority];
statusText = STATUS.Aborted;
}
else if (isEmpty) {
statusText = STATUS.Empty;
}
else if (status !== STATUS.Running && test.isNew) {
statusText = STATUS.New;
}
else {
statusText = status;
}
return { status, statusText };
}
exports.getSingleSessionStatus = getSingleSessionStatus;