UNPKG

@casoon/auditmysite

Version:

A comprehensive command-line tool for automated accessibility, security, performance, and SEO testing using Playwright and pa11y, based on sitemap URLs

275 lines โ€ข 10.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestManager = void 0; const form_label_test_1 = require("./form/form-label-test"); const keyboard_navigation_test_1 = require("./keyboard/keyboard-navigation-test"); const aria_landmarks_test_1 = require("./aria/aria-landmarks-test"); const semantic_html_test_1 = require("./semantic/semantic-html-test"); const media_accessibility_test_1 = require("./media/media-accessibility-test"); const performance_loading_test_1 = require("./performance/performance-loading-test"); const performance_memory_test_1 = require("./performance/performance-memory-test"); const validation_error_handling_test_1 = require("./validation/validation-error-handling-test"); const validation_form_validation_test_1 = require("./validation/validation-form-validation-test"); const language_i18n_test_1 = require("./language/language-i18n-test"); const language_text_direction_test_1 = require("./language/language-text-direction-test"); const seo_meta_test_1 = require("./seo/seo-meta-test"); const seo_content_test_1 = require("./seo/seo-content-test"); const seo_technical_test_1 = require("./seo/seo-technical-test"); class TestManager { constructor() { this.tests = []; this.registerDefaultTests(); } registerDefaultTests() { this.tests = [ new form_label_test_1.FormLabelTest(), new keyboard_navigation_test_1.KeyboardNavigationTest(), new aria_landmarks_test_1.AriaLandmarksTest(), new semantic_html_test_1.SemanticHtmlTest(), new media_accessibility_test_1.MediaAccessibilityTest(), new performance_loading_test_1.PerformanceLoadingTest(), new performance_memory_test_1.PerformanceMemoryTest(), new validation_error_handling_test_1.ValidationErrorHandlingTest(), new validation_form_validation_test_1.ValidationFormValidationTest(), new language_i18n_test_1.LanguageI18nTest(), new language_text_direction_test_1.LanguageTextDirectionTest(), new seo_meta_test_1.SeoMetaTest(), new seo_content_test_1.SeoContentTest(), new seo_technical_test_1.SeoTechnicalTest() ]; } async runAllTests(context) { const results = []; let totalIssues = 0; let totalWarnings = 0; let passedTests = 0; let failedTests = 0; console.log(`๐Ÿงช Running ${this.tests.length} accessibility tests...`); for (let i = 0; i < this.tests.length; i++) { const test = this.tests[i]; const startTime = Date.now(); console.log(` ๐Ÿ” [${i + 1}/${this.tests.length}] ${test.name} (${test.category})...`); try { const result = await test.run(context); const duration = Date.now() - startTime; results.push(result); if (result.passed) { passedTests++; console.log(` โœ… ${test.name} passed in ${duration}ms (${result.errors.length} errors, ${result.warnings.length} warnings)`); } else { failedTests++; console.log(` โŒ ${test.name} failed in ${duration}ms (${result.errors.length} errors, ${result.warnings.length} warnings)`); } totalIssues += result.errors.length; totalWarnings += result.warnings.length; } catch (error) { const duration = Date.now() - startTime; const errorResult = { passed: false, count: 0, errors: [`Test ${test.name} failed: ${error}`], warnings: [] }; results.push(errorResult); failedTests++; totalIssues++; console.log(` ๐Ÿ’ฅ ${test.name} crashed after ${duration}ms: ${error}`); } } const summary = this.generateSummary(results); return { totalTests: this.tests.length, passedTests, failedTests, totalIssues, totalWarnings, results, summary }; } async runTestsByCategory(context, categories) { const filteredTests = this.tests.filter(test => categories.includes(test.category)); const results = []; let totalIssues = 0; let totalWarnings = 0; let passedTests = 0; let failedTests = 0; for (const test of filteredTests) { try { const result = await test.run(context); results.push(result); if (result.passed) { passedTests++; } else { failedTests++; } totalIssues += result.errors.length; totalWarnings += result.warnings.length; } catch (error) { const errorResult = { passed: false, count: 0, errors: [`Test ${test.name} failed: ${error}`], warnings: [] }; results.push(errorResult); failedTests++; totalIssues++; } } const summary = this.generateSummary(results); return { totalTests: filteredTests.length, passedTests, failedTests, totalIssues, totalWarnings, results, summary }; } async runTestsByPriority(context, priorities) { const filteredTests = this.tests.filter(test => priorities.includes(test.priority)); const results = []; let totalIssues = 0; let totalWarnings = 0; let passedTests = 0; let failedTests = 0; for (const test of filteredTests) { try { const result = await test.run(context); results.push(result); if (result.passed) { passedTests++; } else { failedTests++; } totalIssues += result.errors.length; totalWarnings += result.warnings.length; } catch (error) { const errorResult = { passed: false, count: 0, errors: [`Test ${test.name} failed: ${error}`], warnings: [] }; results.push(errorResult); failedTests++; totalIssues++; } } const summary = this.generateSummary(results); return { totalTests: filteredTests.length, passedTests, failedTests, totalIssues, totalWarnings, results, summary }; } generateSummary(results) { const summary = {}; // Group by category const categoryStats = {}; results.forEach(result => { const category = result.details?.category || 'unknown'; if (!categoryStats[category]) { categoryStats[category] = { tests: 0, passed: 0, failed: 0, issues: 0, warnings: 0 }; } categoryStats[category].tests++; if (result.passed) { categoryStats[category].passed++; } else { categoryStats[category].failed++; } categoryStats[category].issues += result.errors.length; categoryStats[category].warnings += result.warnings.length; }); summary.categories = categoryStats; // Overall stats summary.totalIssues = results.reduce((sum, result) => sum + result.errors.length, 0); summary.totalWarnings = results.reduce((sum, result) => sum + result.warnings.length, 0); summary.passedTests = results.filter(result => result.passed).length; summary.failedTests = results.filter(result => !result.passed).length; return summary; } getAvailableTests() { return this.tests.map(test => ({ name: test.name, description: test.description, category: test.category, priority: test.priority, standards: test.standards })); } getAvailableCategories() { return [...new Set(this.tests.map(test => test.category))]; } getAvailablePriorities() { return [...new Set(this.tests.map(test => test.priority))]; } getAvailableStandards() { const allStandards = this.tests.flatMap(test => test.standards); return [...new Set(allStandards)]; } async runTestsByStandard(context, standards) { const filteredTests = this.tests.filter(test => test.standards.some(standard => standards.includes(standard))); const results = []; let totalIssues = 0; let totalWarnings = 0; let passedTests = 0; let failedTests = 0; for (const test of filteredTests) { try { const result = await test.run(context); results.push(result); if (result.passed) { passedTests++; } else { failedTests++; } totalIssues += result.errors.length; totalWarnings += result.warnings.length; } catch (error) { const errorResult = { passed: false, count: 0, errors: [`Test ${test.name} failed: ${error}`], warnings: [] }; results.push(errorResult); failedTests++; totalIssues++; } } const summary = this.generateSummary(results); return { totalTests: filteredTests.length, passedTests, failedTests, totalIssues, totalWarnings, results, summary }; } } exports.TestManager = TestManager; //# sourceMappingURL=test-manager.js.map