#!/usr/bin/env tsx /** * Comprehensive test for embed components */ import { readFileSync, existsSync } from 'fs'; import { join } from 'path'; const componentsDir = join(process.cwd(), 'src', 'components'); interface TestResult { name: string; passed: boolean; details: string; } const results: TestResult[] = []; // Test 1: Check component files exist function testComponentFiles(): TestResult { const files = [ 'YouTubeEmbed.astro', 'TwitterEmbed.astro', 'GenericEmbed.astro' ]; const missing = files.filter(file => !existsSync(join(componentsDir, file))); if (missing.length === 0) { return { name: 'Component Files Exist', passed: true, details: 'All embed components found' }; } return { name: 'Component Files Exist', passed: false, details: `Missing: ${missing.join(', ')}` }; } // Test 2: Check component structure function testComponentStructure(): TestResult { const youtubeContent = readFileSync(join(componentsDir, 'YouTubeEmbed.astro'), 'utf-8'); const twitterContent = readFileSync(join(componentsDir, 'TwitterEmbed.astro'), 'utf-8'); const genericContent = readFileSync(join(componentsDir, 'GenericEmbed.astro'), 'utf-8'); const issues: string[] = []; // Check YouTube structure if (!youtubeContent.includes('interface Props')) issues.push('YouTube: Missing Props interface'); if (!youtubeContent.includes('embedUrl')) issues.push('YouTube: Missing embed URL'); if (!youtubeContent.includes(' { const icon = result.passed ? '✅' : '❌'; console.log(`${icon} ${result.name}`); console.log(` ${result.details}`); if (!result.passed) allPassed = false; }); console.log('\n' + '='.repeat(60)); if (allPassed) { console.log('🎉 All tests passed! Components should work correctly.'); console.log('\nNext steps:'); console.log('1. Visit http://localhost:4321/blog/embed-demo'); console.log('2. Check browser console for any errors'); console.log('3. If Twitter fails, it needs internet during build'); } else { console.log('❌ Some tests failed. Check the details above.'); console.log('\nCommon fixes:'); console.log('- Restart dev server: npm run dev'); console.log('- Check internet connection for Twitter oEmbed'); console.log('- Verify video IDs and tweet IDs are valid'); } process.exit(allPassed ? 0 : 1);