Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -65,16 +71,16 @@ 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')),
).toBe(false);
});
});

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');
}
Expand Down
Loading