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

191 lines (159 loc) โ€ข 7.65 kB
#!/usr/bin/env node /** * ๐Ÿงช Test Enhanced Data in HTML Reports * Verifies that enhanced analysis data correctly flows through to HTML reports */ const { AccessibilityChecker } = require('./dist/core/accessibility'); const { HTMLGenerator } = require('./dist/generators/html-generator'); const fs = require('fs'); const path = require('path'); async function testEnhancedReportData() { console.log('๐Ÿงช Testing enhanced data flow to HTML reports...\n'); const checker = new AccessibilityChecker({ enableComprehensiveAnalysis: true, qualityAnalysisOptions: { verbose: false, includeResourceAnalysis: true, includeTechnicalSEO: true, includeSocialAnalysis: true, analysisTimeout: 30000 } }); await checker.initialize(); console.log('โœ… AccessibilityChecker initialized with comprehensive analysis\n'); const testUrl = 'https://example.com'; try { console.log(`๐Ÿ” Testing: ${testUrl}`); console.log('โ”€'.repeat(60)); const result = await checker.testPage(testUrl, { verbose: false, collectPerformanceMetrics: true, captureScreenshots: false, timeout: 20000 }); console.log('๐Ÿ“Š Analysis completed. Creating audit data structure...'); // Create audit data structure similar to what bin/audit.js creates const auditData = { metadata: { version: '1.0.0', timestamp: new Date().toISOString(), sitemapUrl: testUrl, toolVersion: '2.0.0-alpha.2', duration: result.duration || 30000 }, summary: { totalPages: 1, testedPages: 1, passedPages: result.passed ? 1 : 0, failedPages: result.passed ? 0 : 1, crashedPages: 0, totalErrors: result.errors?.length || 0, totalWarnings: result.warnings?.length || 0, successRate: result.passed ? 100 : 0 }, pages: [{ url: result.url, title: result.title || 'Test Page', status: result.passed ? 'passed' : 'failed', duration: result.duration || 30000, accessibility: { score: result.pa11yScore || 0, errors: result.errors || [], warnings: result.warnings || [], notices: result.notices || [] }, performance: result.enhancedPerformance || result.performance, seo: result.enhancedSEO || result.seo, contentWeight: result.contentWeight, mobileFriendliness: result.mobileFriendliness }] }; // Check what enhanced data we have const page = auditData.pages[0]; console.log('\n๐Ÿ” Enhanced Data Availability Check:'); console.log(` โšก Performance: ${page.performance ? 'โœ… Available' : 'โŒ Missing'}`); console.log(` ๐Ÿ” SEO: ${page.seo ? 'โœ… Available' : 'โŒ Missing'}`); console.log(` ๐Ÿ“ Content Weight: ${page.contentWeight ? 'โœ… Available' : 'โŒ Missing'}`); console.log(` ๐Ÿ“ฑ Mobile Friendliness: ${page.mobileFriendliness ? 'โœ… Available' : 'โŒ Missing'}`); if (page.performance) { console.log(` โ””โ”€ Performance Score: ${page.performance.performanceScore || page.performance.score}/100`); } if (page.seo) { console.log(` โ””โ”€ SEO Score: ${page.seo.overallSEOScore || page.seo.score}/100`); } if (page.contentWeight) { console.log(` โ””โ”€ Content Weight Score: ${page.contentWeight.contentScore || page.contentWeight.score}/100`); } if (page.mobileFriendliness) { console.log(` โ””โ”€ Mobile Score: ${page.mobileFriendliness.overallScore}/100`); } console.log('\n๐Ÿ“ Generating HTML report...'); // Generate HTML report using the HTMLGenerator const htmlGenerator = new HTMLGenerator(); const htmlContent = await htmlGenerator.generate(auditData); // Save the report const reportsDir = path.join(process.cwd(), 'reports', 'test'); if (!fs.existsSync(reportsDir)) { fs.mkdirSync(reportsDir, { recursive: true }); } const reportPath = path.join(reportsDir, `enhanced-data-test-${Date.now()}.html`); fs.writeFileSync(reportPath, htmlContent); console.log(`โœ… HTML report generated: ${reportPath}`); // Parse the HTML to check if enhanced data is present const cheerio = require('cheerio'); const $ = cheerio.load(htmlContent); console.log('\n๐Ÿ” HTML Report Content Verification:'); // Check for performance section const perfSection = $('#performance'); const perfMetrics = perfSection.find('.metric-card .metric-value').length; console.log(` โšก Performance Section: ${perfSection.length > 0 ? 'โœ… Present' : 'โŒ Missing'}`); console.log(` โ””โ”€ Performance Metrics: ${perfMetrics} metric cards found`); // Check for SEO section const seoSection = $('#seo'); const seoMetrics = seoSection.find('.metric-card .metric-value').length; console.log(` ๐Ÿ” SEO Section: ${seoSection.length > 0 ? 'โœ… Present' : 'โŒ Missing'}`); console.log(` โ””โ”€ SEO Metrics: ${seoMetrics} metric cards found`); // Check for content weight section const contentSection = $('#contentweight'); const contentMetrics = contentSection.find('.metric-card .metric-value').length; console.log(` ๐Ÿ“ Content Weight Section: ${contentSection.length > 0 ? 'โœ… Present' : 'โŒ Missing'}`); console.log(` โ””โ”€ Content Metrics: ${contentMetrics} metric cards found`); // Check for mobile section const mobileSection = $('#mobile'); const mobileMetrics = mobileSection.find('.metric-card .metric-value').length; console.log(` ๐Ÿ“ฑ Mobile Section: ${mobileSection.length > 0 ? 'โœ… Present' : 'โŒ Missing'}`); console.log(` โ””โ”€ Mobile Metrics: ${mobileMetrics} metric cards found`); // Check for specific data values (not "N/A" or empty) const performanceScoreElement = $('.metric-label:contains("Performance Score")').parent().find('.metric-value'); const seoScoreElement = $('.metric-label:contains("SEO Score")').parent().find('.metric-value'); if (performanceScoreElement.length > 0) { const perfScore = performanceScoreElement.text().trim(); console.log(` โ””โ”€ Performance Score in Report: ${perfScore}`); } if (seoScoreElement.length > 0) { const seoScore = seoScoreElement.text().trim(); console.log(` โ””โ”€ SEO Score in Report: ${seoScore}`); } // Summary const hasEnhancedData = perfSection.length > 0 && seoSection.length > 0 && contentSection.length > 0 && mobileSection.length > 0; console.log(`\n๐ŸŽฏ Test Result: ${hasEnhancedData ? 'โœ… SUCCESS' : 'โŒ FAILED'}`); console.log(` Enhanced analysis data successfully flows to HTML reports: ${hasEnhancedData}`); if (hasEnhancedData) { console.log('\n๐ŸŽ‰ All enhanced analysis sections are present in the HTML report!'); console.log(' The fixes successfully ensure enhanced data is displayed even for failed pages.'); } else { console.log('\nโŒ Some enhanced analysis sections are missing from the HTML report.'); console.log(' This indicates an issue with data flow or report generation.'); } } catch (error) { console.error(`โŒ Failed to test ${testUrl}: ${error.message}`); console.error(error.stack); } await checker.cleanup(); console.log('\nโœ… Test completed - all resources cleaned up'); } testEnhancedReportData().catch(error => { console.error('โŒ Test failed:', error); process.exit(1); });