UNPKG

@casoon/auditmysite

Version:

Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe

155 lines 4.59 kB
"use strict"; /** * Result Factory Module * Creates consistent AccessibilityResult and PageTestResult objects */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ResultFactory = void 0; /** * ResultFactory - Centralized result object creation * * Responsibilities: * - Create consistent AccessibilityResult objects * - Create PageTestResult objects * - Handle error scenarios uniformly * - Reduce code duplication */ class ResultFactory { /** * Create a skipped result for redirected URLs */ static createRedirectResult(redirectInfo, duration) { const { originalUrl, finalUrl, statusCode } = redirectInfo; return { url: originalUrl, title: 'Redirected', accessibilityResult: { url: originalUrl, title: 'Redirected', imagesWithoutAlt: 0, buttonsWithoutLabel: 0, headingsCount: 0, errors: [ `HTTP Redirect detected: ${originalUrl}${finalUrl} (${statusCode || 'unknown'})` ], warnings: [], passed: false, crashed: false, skipped: true, duration }, comprehensiveAnalysis: undefined, duration, timestamp: new Date() }; } /** * Create an error result for failed tests */ static createErrorResult(url, error, duration, crashed = true) { const errorMessage = error instanceof Error ? error.message : error; return { url, title: 'Error', accessibilityResult: { url, title: 'Error', imagesWithoutAlt: 0, buttonsWithoutLabel: 0, headingsCount: 0, errors: [`Test failed: ${errorMessage}`], warnings: [], passed: false, crashed, duration }, duration, timestamp: new Date() }; } /** * Create a minimal accessibility result (for URL checks) */ static createMinimalResult(config) { return { url: config.url, title: config.title || 'Untitled', imagesWithoutAlt: 0, buttonsWithoutLabel: 0, headingsCount: 0, errors: [], warnings: [], passed: true, crashed: false, duration: config.duration || 0 }; } /** * Create a base accessibility result with common defaults */ static createBaseAccessibilityResult(url, title) { return { url, title, imagesWithoutAlt: 0, buttonsWithoutLabel: 0, headingsCount: 0, errors: [], warnings: [], passed: true, duration: 0 }; } /** * Create a 404 result */ static create404Result(url, duration) { return { url, title: 'Not Found', imagesWithoutAlt: 0, buttonsWithoutLabel: 0, headingsCount: 0, errors: ['HTTP 404 Not Found'], warnings: [], passed: false, crashed: false, skipped: true, duration }; } /** * Create an HTTP error result */ static createHttpErrorResult(url, statusCode, duration) { const result = this.createMinimalResult({ url, duration }); result.passed = false; result.skipped = true; if (statusCode === 404) { result.errors.push('HTTP 404 Not Found'); } else if (statusCode >= 300 && statusCode < 400) { result.errors.push(`HTTP ${statusCode} Redirect`); } else if (statusCode >= 400) { result.errors.push(`HTTP ${statusCode} Error`); } return result; } /** * Add redirect metadata to result */ static addRedirectInfo(result, redirectInfo) { if (redirectInfo.isRedirect) { result.redirectInfo = { status: redirectInfo.statusCode, originalUrl: redirectInfo.originalUrl, finalUrl: redirectInfo.finalUrl, type: redirectInfo.redirectType || 'http_redirect' }; } return result; } } exports.ResultFactory = ResultFactory; //# sourceMappingURL=result-factory.js.map