diff --git a/packages/astro/e2e/astro-island-hydration-error.test.js b/packages/astro/e2e/astro-island-hydration-error.test.ts similarity index 82% rename from packages/astro/e2e/astro-island-hydration-error.test.js rename to packages/astro/e2e/astro-island-hydration-error.test.ts index 5ec252ed5f98..95e0f3390e9d 100644 --- a/packages/astro/e2e/astro-island-hydration-error.test.js +++ b/packages/astro/e2e/astro-island-hydration-error.test.ts @@ -1,12 +1,18 @@ import { expect } from '@playwright/test'; -import { testFactory, waitForHydrate } from './test-utils.js'; +import { type DevServer, testFactory, waitForHydrate } from './test-utils.ts'; + +declare global { + interface Window { + __hydrationErrorEvents?: Array<{ componentUrl: string; hasError: boolean }>; + } +} const test = testFactory(import.meta.url, { root: './fixtures/astro-island-hydration-error/', }); test.describe('astro-island hydration error handling', () => { - let devServer; + let devServer: DevServer; test.beforeAll(async ({ astro }) => { devServer = await astro.startDevServer(); @@ -49,8 +55,8 @@ test.describe('astro-island hydration error handling', () => { const html = await (await page.request.get(pageUrl)).text(); const componentUrl = getIslandComponentUrl(html); - const pageErrors = []; - const consoleErrors = []; + const pageErrors: string[] = []; + const consoleErrors: string[] = []; page.on('pageerror', (error) => pageErrors.push(error.message)); page.on('console', (message) => { if (message.type() === 'error') consoleErrors.push(message.text()); @@ -65,7 +71,7 @@ test.describe('astro-island hydration error handling', () => { const hydrationErrors = await page.evaluate(() => window.__hydrationErrorEvents); expect(hydrationErrors).toHaveLength(1); - expect(hydrationErrors[0].componentUrl).toContain(componentUrl.split('?')[0]); + expect(hydrationErrors![0].componentUrl).toContain(componentUrl.split('?')[0]); expect(pageErrors).toEqual([]); expect( consoleErrors.some((message) => message.includes('[astro-island] Error hydrating')), @@ -73,8 +79,8 @@ test.describe('astro-island hydration error handling', () => { }); }); -function getIslandComponentUrl(html) { - const match = html.match(/component-url="([^"]+)"/); +function getIslandComponentUrl(html: string): string { + const match = /component-url="([^"]+)"/.exec(html); if (!match) { throw new Error('Failed to find astro-island component-url in page HTML'); }