fix: prove resilient keyboard and no-script paths
This commit is contained in:
@@ -14,6 +14,17 @@ interface DocumentSnapshot {
|
||||
};
|
||||
}
|
||||
|
||||
const generatedClientEntry = (rawHtml: string): string => {
|
||||
const entries = [
|
||||
...rawHtml.matchAll(
|
||||
/<script\b(?=[^>]*\btype="module")(?=[^>]*\bsrc="([^"]+)")[^>]*><\/script>/gu,
|
||||
),
|
||||
].map((match) => match[1]);
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0]).toMatch(/^\/assets\/[^/]+\.js$/u);
|
||||
return entries[0]!;
|
||||
};
|
||||
|
||||
const captureDocument = async (
|
||||
page: import('@playwright/test').Page,
|
||||
): Promise<DocumentSnapshot> =>
|
||||
@@ -58,6 +69,7 @@ test('hydration preserves the built subject matter and landmark structure withou
|
||||
const pageErrors: string[] = [];
|
||||
const consoleErrors: string[] = [];
|
||||
const failedRequests: string[] = [];
|
||||
const nonSuccessfulResponses: string[] = [];
|
||||
const requests: string[] = [];
|
||||
page.on('pageerror', (error) => pageErrors.push(error.message));
|
||||
page.on('console', (message) => {
|
||||
@@ -69,6 +81,11 @@ test('hydration preserves the built subject matter and landmark structure withou
|
||||
`${request.url()}: ${request.failure()?.errorText ?? 'failed'}`,
|
||||
),
|
||||
);
|
||||
page.on('response', (response) => {
|
||||
if (response.status() < 200 || response.status() >= 300) {
|
||||
nonSuccessfulResponses.push(`${response.status()} ${response.url()}`);
|
||||
}
|
||||
});
|
||||
await page.addInitScript(() => {
|
||||
const unhandled: string[] = [];
|
||||
Reflect.set(globalThis, '__portfolioUnhandledRejections', unhandled);
|
||||
@@ -120,6 +137,7 @@ test('hydration preserves the built subject matter and landmark structure withou
|
||||
expect(consoleErrors).toEqual([]);
|
||||
expect(unhandledRejections).toEqual([]);
|
||||
expect(failedRequests).toEqual([]);
|
||||
expect(nonSuccessfulResponses).toEqual([]);
|
||||
expect(requests.length).toBeGreaterThan(1);
|
||||
expect(
|
||||
requests.every((requestUrl) => {
|
||||
@@ -131,3 +149,87 @@ test('hydration preserves the built subject matter and landmark structure withou
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('an aborted generated client entry leaves the complete SSR portfolio usable', async ({
|
||||
page,
|
||||
distUrl,
|
||||
request,
|
||||
}, testInfo) => {
|
||||
test.skip(
|
||||
testInfo.project.name === 'mobile-chromium',
|
||||
'The exact entry-failure boundary is viewport-independent; mobile no-script and skip activation run separately.',
|
||||
);
|
||||
|
||||
const rawResponse = await request.get(`${distUrl}/`);
|
||||
expect(rawResponse.status()).toBe(200);
|
||||
const rawHtml = await rawResponse.text();
|
||||
const entryUrl = new URL(generatedClientEntry(rawHtml), distUrl).href;
|
||||
const expectedText = await page.evaluate((html) => {
|
||||
const document = new DOMParser().parseFromString(html, 'text/html');
|
||||
return (document.querySelector('.portfolio-shell')?.textContent ?? '')
|
||||
.replace(/\s+/gu, ' ')
|
||||
.trim();
|
||||
}, rawHtml);
|
||||
|
||||
const pageErrors: string[] = [];
|
||||
const consoleErrors: string[] = [];
|
||||
const failedRequests: Array<{ url: string; error: string }> = [];
|
||||
const nonSuccessfulResponses: string[] = [];
|
||||
page.on('pageerror', (error) => pageErrors.push(error.message));
|
||||
page.on('console', (message) => {
|
||||
if (message.type() === 'error') consoleErrors.push(message.text());
|
||||
});
|
||||
page.on('requestfailed', (request) =>
|
||||
failedRequests.push({
|
||||
url: request.url(),
|
||||
error: request.failure()?.errorText ?? 'failed',
|
||||
}),
|
||||
);
|
||||
page.on('response', (response) => {
|
||||
if (response.status() < 200 || response.status() >= 300) {
|
||||
nonSuccessfulResponses.push(`${response.status()} ${response.url()}`);
|
||||
}
|
||||
});
|
||||
await page.addInitScript(() => {
|
||||
const unhandled: string[] = [];
|
||||
Reflect.set(globalThis, '__portfolioUnhandledRejections', unhandled);
|
||||
addEventListener('unhandledrejection', (event) =>
|
||||
unhandled.push(String(event.reason)),
|
||||
);
|
||||
});
|
||||
await page.route(entryUrl, (route) => route.abort('failed'));
|
||||
|
||||
await page.goto(distUrl, { waitUntil: 'load' });
|
||||
|
||||
const appMounted = await page
|
||||
.locator('#app')
|
||||
.evaluate((app) => Reflect.has(app, '__vue_app__'));
|
||||
const unhandledRejections = await page.evaluate(
|
||||
() =>
|
||||
(Reflect.get(globalThis, '__portfolioUnhandledRejections') as
|
||||
string[] | undefined) ?? [],
|
||||
);
|
||||
expect(appMounted).toBe(false);
|
||||
expect((await captureDocument(page)).text).toBe(expectedText);
|
||||
expect(failedRequests).toEqual([{ url: entryUrl, error: 'net::ERR_FAILED' }]);
|
||||
expect(pageErrors).toEqual([]);
|
||||
expect(unhandledRejections).toEqual([]);
|
||||
expect(nonSuccessfulResponses).toEqual([]);
|
||||
expect(
|
||||
consoleErrors.every((message) =>
|
||||
/Failed to load resource.*ERR_FAILED/iu.test(message),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(consoleErrors.length).toBeLessThanOrEqual(1);
|
||||
|
||||
await expect(page.locator('h1')).toHaveText('Luca Pîslaru');
|
||||
await expect(page.locator('main > section')).toHaveCount(8);
|
||||
await expect(page.locator('nav a')).toHaveCount(8);
|
||||
await expect(
|
||||
page.locator('a[href="mailto:luca.pislaru@gmail.com"]'),
|
||||
).toBeVisible();
|
||||
await page.locator('nav a[href="#contact"]').click();
|
||||
await expect(page).toHaveURL(`${distUrl}/#contact`);
|
||||
await expect(page.locator('#contact')).toBeInViewport();
|
||||
await expect(page.locator('#contact a[href^="mailto:"]')).toBeVisible();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user