Files
archie/e2e/checks/routes.cjs
T

37 lines
1.4 KiB
JavaScript

// Every static route loads without errors, renders, and shows no text with
// stray leading, trailing or doubled spaces.
const fs = require('fs');
const path = require('path');
function routes() {
const src = fs.readFileSync(path.join(__dirname, '../../ui/src/router/index.ts'), 'utf8');
const out = [];
for (const line of src.split('\n')) {
if (/redirect:/.test(line)) continue;
const m = line.match(/path: "([^"]*)"/);
if (!m || m[1].includes(':')) continue;
if (m[1].startsWith('/')) out.push(m[1]);
else if (m[1]) out.push('/org/' + m[1]);
}
return [...new Set(out)];
}
module.exports = async ({ page, go, shot, fail }) => {
const stray = new Map();
for (const r of routes()) {
await go(r);
await shot(r);
// Log lines are data, not copy.
if (r === '/logs') continue;
const bad = await page.evaluate(() => [...document.querySelectorAll('body *')]
.filter((el) => !el.children.length && !el.closest('pre,code,textarea,.xterm') && el.getClientRects().length && !getComputedStyle(el).whiteSpace.startsWith('pre'))
.map((el) => el.textContent)
.filter((t) => t.trim() && (t !== t.trim() || / /.test(t.trim()))));
for (const t of bad) {
const key = JSON.stringify(t.length > 60 ? t.slice(0, 60) + '…' : t);
stray.set(key, (stray.get(key) || new Set()).add(r));
}
}
for (const [text, where] of stray) fail(`stray whitespace ${text} on ${[...where].join(', ')}`);
};