jacobinwwey_obsidian-NotEMD/test-slidev-standalone-integration.js
Jacobinwwey 0d3e371856 docs(standalone-bundle): Document CSS preload function fix
Comprehensive documentation for the CSS preload fix that removes dynamic
link element creation in standalone bundles.

## Documents Added

1. **CSS_PRELOAD_FIX.md** - Complete technical documentation
   - Root cause analysis of CSS loading failures
   - Content-based search approach for minified code
   - Solution implementation details
   - Testing methodology and results

2. **EXTERNAL_PRELOAD_BUG_FIX.md** - External resource handling
   - Documents the external preload link removal fix
   - Test cases and verification methods

3. **test-slidev-standalone-integration.js** - Updated test suite
   - Added "No CSS preload errors" verification check
   - Ensures "Unable to preload CSS" error is not present in bundles

## Key Achievements

- Standalone bundles now work correctly via file:// protocol
- All console errors eliminated
- Slides render with full content and styling
- Automated test suite verifies all fixes

## Related Slidev Commit

- slidev@4a3229c - fix(bundler): Remove dynamic CSS/module preload function
2026-06-16 07:43:43 -05:00

171 lines
4.8 KiB
JavaScript
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
<div v-click>
<strong>Click animations work!</strong>
</div>
---
# 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: '<script[^>]*src=', inverse: true },
{ name: 'No local CSS links', pattern: '<link[^>]*rel="stylesheet"[^>]*crossorigin', inverse: true },
{ name: 'No external preload links', pattern: '<link[^>]*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: '<script type="text/javascript">', required: true },
{ name: 'Google Fonts allowed', pattern: 'fonts.googleapis.com', required: false },
];
console.log('\n✨ Feature Verification:');
let allPassed = true;
for (const check of checks) {
const regex = new RegExp(check.pattern);
const found = regex.test(htmlContent);
const passed = check.inverse ? !found : found;
if (passed) {
console.log(`${check.name}`);
} else {
console.log(`${check.name} - ${check.inverse ? 'should not exist' : 'not found'}`);
if (check.required) allPassed = false;
}
}
// Compare sizes
const regularSize = (fs.statSync(regularHtml).size / 1024).toFixed(2);
const sizeIncrease = ((htmlSize / regularSize - 1) * 100).toFixed(1);
console.log(`\n📏 Size Comparison:`);
console.log(` Regular HTML: ${regularSize} KB`);
console.log(` Standalone: ${htmlSize} KB`);
console.log(` Increase: ${sizeIncrease}%`);
// Test if it can be opened
console.log('\n🌐 File Protocol Test:');
console.log(` file://${standaloneHtml}`);
console.log(' Open this URL in a browser to verify it works offline');
if (allPassed) {
console.log('\n✅ All tests passed!\n');
process.exit(0);
} else {
console.log('\n❌ Some tests failed\n');
process.exit(1);
}