#!/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: '