#!/usr/bin/env node /** * Integration test for Slidev standalone bundle export * Tests the new --standalone-bundle flag with real markdown files */ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); const SLIDEV_BIN = '/home/jacob/slidev/packages/slidev/bin/slidev.mjs'; const TEST_DIR = path.join(__dirname, 'docs/export/test-standalone-integration'); const TEST_MD = path.join(TEST_DIR, 'test-slides.md'); // Test markdown content const testContent = `--- theme: default class: text-center highlighter: shiki title: Integration Test Slides --- # Integration Test Testing Slidev standalone bundle with obsidian-NotEMD --- # Code Example \`\`\`typescript interface User { id: number; name: string; } function greet(user: User): string { return \`Hello, \${user.name}!\`; } \`\`\` --- # Vue Components
Click animations work!
--- # Mermaid Diagram \`\`\`mermaid graph TD A[Start] --> B[Process] B --> C[End] \`\`\` --- # Final Slide โœ… Test complete! `; console.log('๐Ÿงช Slidev Standalone Bundle Integration Test\n'); // Create test directory if (!fs.existsSync(TEST_DIR)) { fs.mkdirSync(TEST_DIR, { recursive: true }); console.log('โœ… Created test directory'); } // Write test markdown fs.writeFileSync(TEST_MD, testContent); console.log('โœ… Created test markdown file'); // Run Slidev build with --standalone-bundle console.log('\n๐Ÿ“ฆ Building standalone bundle...'); try { const startTime = Date.now(); const output = execSync( `node ${SLIDEV_BIN} build --standalone-bundle --out dist ${TEST_MD}`, { cwd: TEST_DIR, encoding: 'utf-8' } ); const duration = ((Date.now() - startTime) / 1000).toFixed(2); console.log(`โœ… Build completed in ${duration}s`); } catch (error) { console.error('โŒ Build failed:', error.message); process.exit(1); } // Verify output files const distDir = path.join(TEST_DIR, 'dist'); const standaloneHtml = path.join(distDir, 'index-standalone.html'); const regularHtml = path.join(distDir, 'index.html'); console.log('\n๐Ÿ” Verifying output files...'); if (!fs.existsSync(standaloneHtml)) { console.error('โŒ index-standalone.html not found'); process.exit(1); } console.log('โœ… index-standalone.html exists'); if (!fs.existsSync(regularHtml)) { console.error('โŒ index.html not found'); process.exit(1); } console.log('โœ… index.html exists'); // Read and analyze standalone bundle const htmlContent = fs.readFileSync(standaloneHtml, 'utf-8'); const htmlSize = (fs.statSync(standaloneHtml).size / 1024).toFixed(2); console.log(`\n๐Ÿ“Š Standalone Bundle Analysis:`); console.log(` Size: ${htmlSize} KB`); // Check for critical features const checks = [ { name: 'Bundle mode marker', pattern: 'slidev-bundle-mode', required: true }, { name: 'Module loader (__require)', pattern: '__require', required: true }, { name: 'Critical export fix', pattern: 'module.exports.default=module.exports=', required: true }, { name: 'No external scripts', pattern: ']*src=', inverse: true }, { name: 'No local CSS links', pattern: ']*rel="stylesheet"[^>]*crossorigin', inverse: true }, { name: 'No external preload links', pattern: ']*rel="preload"[^>]*href="https?://', inverse: true }, { name: 'No CSS preload errors', pattern: 'Unable to preload CSS', inverse: true }, { name: 'Vue component code', pattern: 'Vue', required: true }, { name: 'Slide content', pattern: 'Integration Test', required: true }, { name: 'Inline scripts present', pattern: '