Files
cv-site/tests/archive/hyperscript/test-hyperscript-fix.mjs
T

142 lines
4.0 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env bun
import { chromium } from "playwright";
const URL = "http://localhost:1999";
async function testHyperscriptFix() {
console.log("🧪 Testing Hyperscript Fix\n");
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
const errors = [];
const warnings = [];
// Capture all console messages
page.on('console', msg => {
const text = msg.text();
if (msg.type() === 'error') {
errors.push(text);
console.log(`❌ ERROR: ${text}`);
} else if (msg.type() === 'warning') {
warnings.push(text);
}
});
// Capture page errors
page.on('pageerror', err => {
errors.push(err.message);
console.log(`❌ PAGE ERROR: ${err.message}`);
});
console.log("1️⃣ Loading page...");
await page.goto(URL);
await page.waitForTimeout(2000);
// Check for parse errors specifically
const hasParseError = errors.some(e =>
e.includes("Expected 'end' but found 'def'") ||
e.includes("parse error")
);
console.log("\n2️⃣ Checking hyperscript functions...");
// Check if functions are defined
const functionsCheck = await page.evaluate(() => {
const functions = [
'printFriendly',
'initScrollBehavior',
'handleScroll',
'toggleCVLength',
'toggleIcons',
'toggleTheme',
'syncPdfHover',
'syncPrintHover',
'highlightZoomControl'
];
const results = {};
for (const fn of functions) {
// Check if function exists in hyperscript runtime
results[fn] = typeof window[fn] !== 'undefined' ||
(window._hyperscript && window._hyperscript.internals &&
window._hyperscript.internals.runtime &&
window._hyperscript.internals.runtime.commands &&
window._hyperscript.internals.runtime.commands[fn]);
}
return results;
});
console.log("\n3️⃣ Testing toggle functionality...");
// Test length toggle
const lengthToggle = await page.$('#lengthToggle');
if (lengthToggle) {
const paper = await page.$('.cv-paper');
const beforeClass = await paper.evaluate(el => el.className);
await lengthToggle.click();
await page.waitForTimeout(500);
const afterClass = await paper.evaluate(el => el.className);
const toggleWorks = beforeClass !== afterClass;
console.log(` Length toggle: ${toggleWorks ? '✅ Works' : '❌ Broken'}`);
} else {
console.log(` Length toggle: ❌ Not found`);
}
console.log("\n4️⃣ Checking button visibility...");
const buttons = await page.evaluate(() => {
return {
hamburger: !!document.querySelector('.hamburger-btn'),
lengthToggle: !!document.querySelector('#lengthToggle'),
logoToggle: !!document.querySelector('#logoToggle'),
themeToggle: !!document.querySelector('#themeToggle'),
pdfBtn: !!document.querySelector('.pdf-btn'),
printBtn: !!document.querySelector('.print-btn')
};
});
const visibleCount = Object.values(buttons).filter(v => v).length;
console.log(` Visible buttons: ${visibleCount}/6`);
for (const [name, visible] of Object.entries(buttons)) {
console.log(` ${visible ? '✅' : '❌'} ${name}`);
}
await browser.close();
console.log("\n" + "=".repeat(50));
console.log("📊 RESULTS\n");
if (hasParseError) {
console.log("❌ PARSE ERROR DETECTED");
console.log(" The 'Expected end but found def' error is still present");
return false;
} else {
console.log("✅ NO PARSE ERRORS");
}
if (errors.length === 0) {
console.log("✅ NO CONSOLE ERRORS");
} else {
console.log(`⚠️ ${errors.length} console errors found`);
errors.forEach(e => console.log(` - ${e}`));
}
if (visibleCount === 6) {
console.log("✅ ALL 6 BUTTONS VISIBLE");
} else {
console.log(`❌ ONLY ${visibleCount}/6 BUTTONS VISIBLE`);
}
console.log("=".repeat(50) + "\n");
return !hasParseError && errors.length === 0 && visibleCount === 6;
}
const success = await testHyperscriptFix();
process.exit(success ? 0 : 1);