Skip to content

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

test(docs): serve a local stand-in for the shields.io badge in browser tests (#4383)

Worktrunk Botcd5d51dbd598
diff --git a/docs/tests/browser-site.test.mjs b/docs/tests/browser-site.test.mjs
index 365820bfe..76e00d1f2 100644
--- a/docs/tests/browser-site.test.mjs
+++ b/docs/tests/browser-site.test.mjs
@@ -59,6 +59,20 @@ async function openPage(page, url) {
await page.evaluate(() => document.fonts.ready);
}
+// Every page header carries the shields.io GitHub-stars badge, the one
+// third-party resource besides the web fonts. Serve a stand-in at the badge's
+// declared size so `load` waits only on the local server and the fonts.
+const starsBadge = '<svg xmlns="http://www.w3.org/2000/svg" width="90" height="20"></svg>';
+
+async function newPage(browser, options) {
+ const page = await browser.newPage(options);
+ await page.route('https://img.shields.io/**', (route) => route.fulfill({
+ contentType: 'image/svg+xml',
+ body: starsBadge,
+ }));
+ return page;
+}
+
function rgbChannels(value) {
const channels = value.match(/[\d.]+/gu).slice(0, 3).map(Number);
return value.startsWith('color(srgb')
@@ -90,7 +104,7 @@ test('mobile pages stay viewport-bound while code remains readable', { timeout:
try {
for (const theme of ['light', 'dark']) {
for (const width of mobileWidths) {
- const page = await browser.newPage({ viewport: { width, height: 844 }, colorScheme: theme });
+ const page = await newPage(browser, { viewport: { width, height: 844 }, colorScheme: theme });
for (const route of publicRoutes) {
await openPage(page, `${baseUrl}${route}`);
await page.evaluate((selectedTheme) => {
@@ -196,7 +210,7 @@ test('desktop code examples fit the content column', { timeout: 60_000 }, async
const browser = await webkit.launch();
try {
for (const width of [1152, 1376, 1401, 1920]) {
- const page = await browser.newPage({ viewport: { width, height: 900 } });
+ const page = await newPage(browser, { viewport: { width, height: 900 } });
for (const route of await sitemapRoutes()) {
await openPage(page, `${baseUrl}${route}`);
const { column, blocks, terminals } = await page.evaluate(() => {
@@ -235,7 +249,7 @@ test('desktop code examples fit the content column', { timeout: 60_000 }, async
await page.close();
}
- const page = await browser.newPage({ viewport: { width: 1920, height: 900 } });
+ const page = await newPage(browser, { viewport: { width: 1920, height: 900 } });
await openPage(page, baseUrl + '/');
const rail = await page.evaluate(() => {
const frame = [...document.querySelectorAll('.expressive-code .frame')]
@@ -287,7 +301,7 @@ test('copy buttons sit in view on the line they copy without overlapping', { tim
const browser = await webkit.launch();
try {
for (const { width, touch } of [{ width: 393, touch: true }, { width: 1376, touch: false }]) {
- const page = await browser.newPage({
+ const page = await newPage(browser, {
viewport: { width, height: 900 },
hasTouch: touch,
isMobile: touch,
@@ -343,7 +357,7 @@ test('code artifacts keep their visual hierarchy in both themes', async () => {
const browser = await webkit.launch();
try {
for (const theme of ['light', 'dark']) {
- const page = await browser.newPage({ viewport: { width: 1280, height: 900 }, colorScheme: theme });
+ const page = await newPage(browser, { viewport: { width: 1280, height: 900 }, colorScheme: theme });
await openPage(page, `${baseUrl}/claude-code/`);
await page.evaluate((selectedTheme) => {