Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

test(docs): wait for web fonts before browser layout checks (#4382)

Worktrunk Botdc97142974e8
diff --git a/docs/tests/browser-site.test.mjs b/docs/tests/browser-site.test.mjs
index 059b5f0ec..365820bfe 100644
--- a/docs/tests/browser-site.test.mjs
+++ b/docs/tests/browser-site.test.mjs
@@ -51,6 +51,14 @@ async function sitemapRoutes() {
.map((match) => new URL(match[1]).pathname);
}
+// Layout checks measure the page as set in its web fonts. The stylesheet loads
+// them with `display=swap`, so at DOMContentLoaded text can still be in a wider
+// fallback face, and a terminal sized to the column overflows it.
+async function openPage(page, url) {
+ await page.goto(url, { waitUntil: 'load' });
+ await page.evaluate(() => document.fonts.ready);
+}
+
function rgbChannels(value) {
const channels = value.match(/[\d.]+/gu).slice(0, 3).map(Number);
return value.startsWith('color(srgb')
@@ -84,7 +92,7 @@ test('mobile pages stay viewport-bound while code remains readable', { timeout:
for (const width of mobileWidths) {
const page = await browser.newPage({ viewport: { width, height: 844 }, colorScheme: theme });
for (const route of publicRoutes) {
- await page.goto(`${baseUrl}${route}`, { waitUntil: 'domcontentloaded' });
+ await openPage(page, `${baseUrl}${route}`);
await page.evaluate((selectedTheme) => {
document.documentElement.dataset.theme = selectedTheme;
}, theme);
@@ -190,7 +198,7 @@ test('desktop code examples fit the content column', { timeout: 60_000 }, async
for (const width of [1152, 1376, 1401, 1920]) {
const page = await browser.newPage({ viewport: { width, height: 900 } });
for (const route of await sitemapRoutes()) {
- await page.goto(`${baseUrl}${route}`, { waitUntil: 'domcontentloaded' });
+ await openPage(page, `${baseUrl}${route}`);
const { column, blocks, terminals } = await page.evaluate(() => {
const { left, right } = document.querySelector('.sl-markdown-content').getBoundingClientRect();
return {
@@ -228,7 +236,7 @@ test('desktop code examples fit the content column', { timeout: 60_000 }, async
}
const page = await browser.newPage({ viewport: { width: 1920, height: 900 } });
- await page.goto(baseUrl + '/', { waitUntil: 'domcontentloaded' });
+ await openPage(page, baseUrl + '/');
const rail = await page.evaluate(() => {
const frame = [...document.querySelectorAll('.expressive-code .frame')]
.find((candidate) => candidate.querySelector('.wt-command')?.textContent.trim() === 'wt list');
@@ -285,7 +293,7 @@ test('copy buttons sit in view on the line they copy without overlapping', { tim
isMobile: touch,
});
for (const route of await sitemapRoutes()) {
- await page.goto(`${baseUrl}${route}`, { waitUntil: 'domcontentloaded' });
+ await openPage(page, `${baseUrl}${route}`);
const frames = await page.evaluate(() => {
for (const details of document.querySelectorAll('.sl-markdown-content details')) details.open = true;
return [...document.querySelectorAll('.expressive-code .frame')].map((frame) => {
@@ -337,7 +345,7 @@ test('code artifacts keep their visual hierarchy in both themes', async () => {
for (const theme of ['light', 'dark']) {
const page = await browser.newPage({ viewport: { width: 1280, height: 900 }, colorScheme: theme });
- await page.goto(`${baseUrl}/claude-code/`, { waitUntil: 'domcontentloaded' });
+ await openPage(page, `${baseUrl}/claude-code/`);
await page.evaluate((selectedTheme) => {
document.documentElement.dataset.theme = selectedTheme;
}, theme);
@@ -366,7 +374,7 @@ test('code artifacts keep their visual hierarchy in both themes', async () => {
assert.ok(ratio >= 4.5, `${theme} shell token ${text} contrast is ${ratio.toFixed(2)}:1`);
}
- await page.goto(baseUrl + '/', { waitUntil: 'domcontentloaded' });
+ await openPage(page, baseUrl + '/');
await page.evaluate((selectedTheme) => {
document.documentElement.dataset.theme = selectedTheme;
}, theme);
@@ -461,7 +469,7 @@ test('code artifacts keep their visual hierarchy in both themes', async () => {
);
}
- await page.goto(`${baseUrl}/list/`, { waitUntil: 'domcontentloaded' });
+ await openPage(page, `${baseUrl}/list/`);
await page.evaluate((selectedTheme) => {
document.documentElement.dataset.theme = selectedTheme;
}, theme);
@@ -507,7 +515,7 @@ test('code artifacts keep their visual hierarchy in both themes', async () => {
assert.ok(ratio >= 4.5, `${theme} help-role contrast is ${ratio.toFixed(2)}:1`);
}
- await page.goto(`${baseUrl}/config/`, { waitUntil: 'domcontentloaded' });
+ await openPage(page, `${baseUrl}/config/`);
await page.evaluate((selectedTheme) => {
document.documentElement.dataset.theme = selectedTheme;
}, theme);