1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>homepage layout regression</title>
<p>Serve this page on the same origin as the Caddy-rendered homepage. Checks use the real page and live data.</p>
<pre id="results">running</pre>
<script>
const results = document.getElementById('results');
async function check(width) {
const frame = document.createElement('iframe');
frame.style.cssText = `width:${width}px;height:844px;border:0;display:block`;
const loaded = new Promise(resolve => frame.addEventListener('load', resolve, {once:true}));
frame.src = '/';
document.body.append(frame);
await loaded;
try {
const doc = frame.contentDocument;
const win = frame.contentWindow;
const river = doc.getElementById('river');
if (!river) throw new Error('homepage did not render');
for (let i = 0; i < 30 && !river.textContent.trim(); i++) {
await new Promise(resolve => setTimeout(resolve, 100));
}
if (!river.textContent.trim()) throw new Error('river did not draw');
if (!doc.querySelector('.ep')) throw new Error('endpoint list did not render');
for (let i = 0; i < 2; i++) {
if (doc.documentElement.scrollWidth > doc.documentElement.clientWidth) {
throw new Error(`page overflows: ${doc.documentElement.scrollWidth} > ${doc.documentElement.clientWidth}`);
}
const bounds = river.getBoundingClientRect();
if (bounds.left < 0 || bounds.right > width) throw new Error('river exceeds viewport');
const sizes = new Set(Array.from(doc.querySelectorAll('.ep .p, .ep .d, .ep .m'), line => win.getComputedStyle(line).fontSize));
if (sizes.size !== 1) throw new Error('endpoint text sizes differ');
for (const line of doc.querySelectorAll('.ep .p, .ep .d, .tag')) {
if (line.scrollWidth > line.clientWidth + 1) throw new Error(`text overflows: ${line.textContent}`);
const range = doc.createRange();
range.selectNodeContents(line);
const rows = new Set(Array.from(range.getClientRects(), rect => Math.round(rect.top)));
if (rows.size > 1) throw new Error(`text wraps: ${line.textContent}`);
if (win.getComputedStyle(line).textOverflow === 'ellipsis') throw new Error('text is truncated');
}
win.scrollTo(1000, 0);
if (win.scrollX !== 0) throw new Error(`horizontal scrolling reached ${win.scrollX}`);
win.scrollTo(0, doc.documentElement.scrollHeight);
const atmosphere = doc.getElementById('atmosphere').getBoundingClientRect();
const glass = doc.getElementById('depth').getBoundingClientRect();
if (atmosphere.top !== 0 || atmosphere.bottom < win.innerHeight) throw new Error('background does not cover scrolled viewport');
if (glass.top >= 0 || glass.bottom <= win.innerHeight || glass.left >= 0 || glass.right <= win.innerWidth) {
throw new Error('glass ends at a viewport edge');
}
win.scrollTo(0, 0);
await new Promise(resolve => setTimeout(resolve, 1000));
}
return `${width}px: PASS`;
} finally {
frame.remove();
}
}
(async () => {
const lines = [];
for (const width of [320, 390, 640, 1280]) {
try { lines.push(await check(width)); }
catch (error) { lines.push(`${width}px: FAIL — ${error.message}`); }
results.textContent = lines.join('\n');
}
document.title = lines.some(line => line.includes('FAIL')) ? 'FAIL: homepage layout' : 'PASS: homepage layout';
})();
</script>
</html>