#!/usr/bin/env node /** * Critical Test: Content Rendering Validation * * This test ensures that content actually renders despite any JavaScript enhancements. * It catches JavaScript syntax errors that would prevent basic content display. */ const { TestRunner, HTMLFileTester } = require('./test_runner.js'); const fs = require('fs'); const runner = new TestRunner(); runner.describe('Critical Content Rendering Validation', () => { let htmlTester; const testHtmlPath = '/tmp/test_content_rendering.html'; runner.it('should generate valid HTML that renders content without JavaScript errors', async () => { // Create simple test content const testMarkdown = `# Test Content Rendering This is critical test content that MUST render even if JavaScript fails. ## Basic Content - List item 1 - List item 2 \`\`\`javascript console.log("test"); \`\`\` > Quote content that should be visible Final paragraph content.`; // Write test markdown fs.writeFileSync('/tmp/test_content_source.md', testMarkdown); // Generate HTML using markitect const { execSync } = require('child_process'); try { execSync(`cd /home/worsch/markitect_project && MARKITECT_EDIT_MODE=true markitect md-render /tmp/test_content_source.md --output ${testHtmlPath}`, { stdio: 'pipe' }); runner.expect(fs.existsSync(testHtmlPath)).toBeTruthy(); } catch (error) { throw new Error(`Failed to generate HTML: ${error.message}`); } }); runner.it('should have basic HTML structure with content', async () => { htmlTester = new HTMLFileTester(testHtmlPath); const loaded = await htmlTester.load(); runner.expect(loaded || htmlTester.html).toBeTruthy(); runner.expect(htmlTester.html.length).toBeGreaterThan(1000); // Should have substantial content }); runner.it('should have markdown content available for JavaScript rendering', async () => { // Check that the markdown content is embedded in JavaScript for dynamic rendering runner.expect(htmlTester.html.includes('Test Content Rendering')).toBeTruthy(); // Title in JS string runner.expect(htmlTester.html.includes('Basic Content')).toBeTruthy(); // Subheading in JS string runner.expect(htmlTester.html.includes('List item 1')).toBeTruthy(); // List content in JS string runner.expect(htmlTester.html.includes('Final paragraph')).toBeTruthy(); // Final content in JS string // Check that JavaScript rendering templates are present runner.expect(htmlTester.html.includes('.replace(/^# (.*$)/gim, \'

$1

\')')).toBeTruthy(); // H1 rendering runner.expect(htmlTester.html.includes('.replace(/^## (.*$)/gim, \'

$1

\')')).toBeTruthy(); // H2 rendering runner.expect(htmlTester.html.includes('markdownContent')).toBeTruthy(); // Content variable exists // Check for target container runner.expect(htmlTester.html.includes('id="markdown-content"')).toBeTruthy(); // Target container exists }); runner.it('should not have JavaScript syntax errors that prevent execution', async () => { // Check for common JavaScript syntax issues in the HTML const jsContent = htmlTester.html; // Check for unclosed strings const unclosedStrings = jsContent.match(/['"`][^'"`\n]*[\n]/g); if (unclosedStrings) { console.warn('Potential unclosed strings found:', unclosedStrings.slice(0, 3)); } // Check for mismatched brackets const openBrackets = (jsContent.match(/[({[]/g) || []).length; const closeBrackets = (jsContent.match(/[)}\]]/g) || []).length; // Allow some tolerance for string content const bracketDiff = Math.abs(openBrackets - closeBrackets); runner.expect(bracketDiff).toBeLessThan(10); // Should be reasonably balanced // Check for obvious syntax errors - these are valid syntax patterns // Note: 'function (' with space is valid JavaScript syntax const hasFunctionSyntax = jsContent.includes('function(') || jsContent.includes('function ('); runner.expect(hasFunctionSyntax).toBeTruthy(); // Should have functions const hasProperBraces = jsContent.includes(') {') || jsContent.includes('){'); runner.expect(hasProperBraces).toBeTruthy(); // Should have proper function/if syntax }); runner.it('should have fallback mechanisms for JavaScript failures', async () => { // Test that there are graceful degradation mechanisms in place const markdownContainer = htmlTester.html.match(/]*id=["']markdown-content["'][^>]*>([\s\S]*?)<\/div>/i); runner.expect(markdownContainer).toBeTruthy(); // The container should exist even if initially empty (content is added by JS) const hasContainer = htmlTester.html.includes('id="markdown-content"'); runner.expect(hasContainer).toBeTruthy(); // Should have noscript alternative or error handling const hasGracefulDegradation = htmlTester.html.includes('noscript') || htmlTester.html.includes('try {') || htmlTester.html.includes('catch'); runner.expect(hasGracefulDegradation).toBeTruthy(); }); runner.it('should have fallback content rendering strategy', async () => { // Check for graceful degradation comments or fallback mechanisms const hasFallback = htmlTester.html.includes('graceful') || htmlTester.html.includes('fallback') || htmlTester.html.includes('degradation') || htmlTester.html.includes('