208 lines
7.0 KiB
JavaScript
Executable File
208 lines
7.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
import { chromium } from 'playwright';
|
|
|
|
(async () => {
|
|
console.log('🔬 DEFINITIVE NO-CACHE VERIFICATION TEST\n');
|
|
console.log('Using completely fresh browser profile with aggressive cache busting\n');
|
|
|
|
// Launch with COMPLETELY fresh profile and cache disabled
|
|
const browser = await chromium.launch({
|
|
headless: false,
|
|
args: [
|
|
'--disable-http-cache',
|
|
'--disable-cache',
|
|
'--disable-application-cache',
|
|
'--disable-offline-load-stale-cache',
|
|
'--disk-cache-size=0'
|
|
]
|
|
});
|
|
|
|
const context = await browser.newContext({
|
|
ignoreHTTPSErrors: true,
|
|
bypassCSP: true,
|
|
// Disable all caching at context level
|
|
serviceWorkers: 'block'
|
|
});
|
|
|
|
const page = await context.newPage();
|
|
|
|
// Disable cache at page level too
|
|
await page.route('**/*', route => {
|
|
route.continue({
|
|
headers: {
|
|
...route.request().headers(),
|
|
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
'Pragma': 'no-cache',
|
|
'Expires': '0'
|
|
}
|
|
});
|
|
});
|
|
|
|
const errors = [];
|
|
let parseErrorDetails = null;
|
|
|
|
page.on('console', msg => {
|
|
if (msg.type() === 'error') {
|
|
const text = msg.text();
|
|
errors.push(text);
|
|
if (text.includes('Expected') || text.includes('hyperscript')) {
|
|
parseErrorDetails = text;
|
|
}
|
|
}
|
|
});
|
|
|
|
page.on('pageerror', err => {
|
|
errors.push(err.message);
|
|
if (err.message.includes('Expected') || err.message.includes('hyperscript')) {
|
|
parseErrorDetails = err.message;
|
|
}
|
|
});
|
|
|
|
// Triple cache-busting: timestamp + random + cache headers
|
|
const timestamp = Date.now();
|
|
const random = Math.random().toString(36).substring(7);
|
|
const url = `http://localhost:1999/?lang=en&_t=${timestamp}&_r=${random}`;
|
|
|
|
console.log(`📄 Loading: ${url}\n`);
|
|
console.log('⏳ Waiting for page to fully load...\n');
|
|
|
|
await page.goto(url, {
|
|
waitUntil: 'networkidle',
|
|
timeout: 15000
|
|
});
|
|
|
|
await page.waitForTimeout(4000);
|
|
|
|
console.log('═'.repeat(70));
|
|
console.log('VERIFICATION RESULTS');
|
|
console.log('═'.repeat(70) + '\n');
|
|
|
|
// TEST 1: Check for parse errors
|
|
const hasParseError = errors.some(e =>
|
|
e.includes('Expected') ||
|
|
e.includes('found') ||
|
|
e.toLowerCase().includes('parse')
|
|
);
|
|
|
|
console.log('1. HYPERSCRIPT PARSE ERRORS:');
|
|
if (hasParseError) {
|
|
console.log(' ❌ STILL PRESENT\n');
|
|
console.log(' Error details:');
|
|
console.log(' ' + parseErrorDetails.split('\n').join('\n '));
|
|
console.log('\n ⚠️ This means either:');
|
|
console.log(' - The file still has syntax errors');
|
|
console.log(' - OR there\'s server-side caching we can\'t bypass\n');
|
|
} else {
|
|
console.log(' ✅ NONE FOUND - Parse fix successful!\n');
|
|
}
|
|
|
|
// TEST 2: Verify file content served by server
|
|
console.log('2. SERVER FILE CONTENT CHECK:');
|
|
const fileContent = await page.evaluate(async () => {
|
|
const cacheBuster = Date.now() + Math.random();
|
|
const response = await fetch(`/static/hyperscript/functions._hs?_=${cacheBuster}`, {
|
|
cache: 'no-store',
|
|
headers: {
|
|
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
'Pragma': 'no-cache'
|
|
}
|
|
});
|
|
const text = await response.text();
|
|
|
|
// Find the handleScroll function
|
|
const handleScrollMatch = text.match(/def handleScroll\(\)([\s\S]*?)(?=\ndef\s|\n--\s*={10,})/);
|
|
const handleScrollCode = handleScrollMatch ? handleScrollMatch[0] : '';
|
|
|
|
// Check patterns
|
|
const hasOldIfElse = /if currentScroll > 300[\s\S]{0,100}else[\s\S]{0,100}set #back-to-top/.test(handleScrollCode);
|
|
const hasNewSeparateIfs = /if currentScroll > 300[\s\S]{0,50}end[\s\S]{0,50}if currentScroll <= 300/.test(handleScrollCode);
|
|
|
|
return {
|
|
size: text.length,
|
|
hasHandleScroll: text.includes('def handleScroll()'),
|
|
usesOldIfElse: hasOldIfElse,
|
|
usesNewSeparateIfs: hasNewSeparateIfs,
|
|
handleScrollSnippet: handleScrollCode.substring(0, 500)
|
|
};
|
|
});
|
|
|
|
console.log(` - File size: ${fileContent.size} bytes`);
|
|
console.log(` - Has handleScroll(): ${fileContent.hasHandleScroll ? '✅ YES' : '❌ NO'}`);
|
|
console.log(` - Uses OLD if/else pattern: ${fileContent.usesOldIfElse ? '❌ YES (BAD)' : '✅ NO'}`);
|
|
console.log(` - Uses NEW separate ifs: ${fileContent.usesNewSeparateIfs ? '✅ YES (GOOD)' : '❌ NO'}`);
|
|
|
|
console.log('\n Code snippet from server:');
|
|
console.log(' ' + fileContent.handleScrollSnippet.split('\n').slice(0, 15).join('\n '));
|
|
|
|
// TEST 3: Check if hyperscript loaded
|
|
console.log('\n3. HYPERSCRIPT LIBRARY STATUS:');
|
|
const hsLoaded = await page.evaluate(() => typeof window._hyperscript !== 'undefined');
|
|
console.log(` ${hsLoaded ? '✅ Loaded' : '❌ Not loaded'}`);
|
|
|
|
// TEST 4: Scroll behavior test
|
|
console.log('\n4. FUNCTIONAL TEST - Scroll Behavior:');
|
|
|
|
await page.evaluate(() => window.scrollTo(0, 0));
|
|
await page.waitForTimeout(300);
|
|
|
|
let btnCheck = await page.evaluate(() => {
|
|
const btn = document.querySelector('#back-to-top');
|
|
return {
|
|
exists: !!btn,
|
|
display: btn ? window.getComputedStyle(btn).display : 'N/A'
|
|
};
|
|
});
|
|
|
|
console.log(` - At top (0px): display = "${btnCheck.display}" ${btnCheck.display === 'none' ? '✅' : '❌ Expected "none"'}`);
|
|
|
|
await page.evaluate(() => window.scrollTo(0, 500));
|
|
await page.waitForTimeout(300);
|
|
|
|
btnCheck = await page.evaluate(() => {
|
|
const btn = document.querySelector('#back-to-top');
|
|
return {
|
|
display: btn ? window.getComputedStyle(btn).display : 'N/A'
|
|
};
|
|
});
|
|
|
|
console.log(` - At 500px: display = "${btnCheck.display}" ${btnCheck.display === 'flex' ? '✅' : '❌ Expected "flex"'}`);
|
|
|
|
console.log('\n' + '═'.repeat(70));
|
|
|
|
// FINAL VERDICT
|
|
const allTestsPass = !hasParseError &&
|
|
!fileContent.usesOldIfElse &&
|
|
fileContent.usesNewSeparateIfs &&
|
|
hsLoaded;
|
|
|
|
if (allTestsPass) {
|
|
console.log('✅ SUCCESS: All tests passed!');
|
|
console.log('\n The hyperscript parse error is COMPLETELY FIXED.');
|
|
console.log(' - File uses correct separate if blocks structure');
|
|
console.log(' - No parse errors in browser');
|
|
console.log(' - Hyperscript library loads successfully');
|
|
console.log(' - Scroll behavior works correctly');
|
|
} else {
|
|
console.log('❌ FAILURE: Issues detected');
|
|
if (hasParseError) {
|
|
console.log('\n ⚠️ Parse error persists despite fresh cache');
|
|
console.log(' This indicates the file itself may still have issues');
|
|
}
|
|
if (fileContent.usesOldIfElse) {
|
|
console.log('\n ⚠️ Server is serving OLD if/else pattern');
|
|
console.log(' File on disk may not be saved correctly');
|
|
}
|
|
if (!fileContent.usesNewSeparateIfs) {
|
|
console.log('\n ⚠️ New pattern not detected in served file');
|
|
console.log(' File structure needs verification');
|
|
}
|
|
}
|
|
|
|
console.log('═'.repeat(70));
|
|
console.log('\n💡 Browser window left open for manual inspection');
|
|
console.log(' Check Console tab and scroll the page manually');
|
|
console.log('\nPress Ctrl+C when done\n');
|
|
|
|
await new Promise(() => {});
|
|
})();
|