Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 23 additions & 3 deletions tests/E2E/support/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import type { Page, Response } from '@playwright/test';

function isRetryableNetworkError(error: unknown): boolean {
return /ERR_SSL_PROTOCOL_ERROR|ERR_NETWORK_CHANGED/.test(String(error));
}

export async function gotoWithTlsRetry(
page: Page,
url: string,
): Promise<Response | null> {
for (let attempt = 1; attempt <= 4; attempt += 1) {
for (let attempt = 1; attempt <= 8; attempt += 1) {
try {
return await page.goto(url);
} catch (error) {
if (
attempt === 4 ||
!String(error).includes('ERR_SSL_PROTOCOL_ERROR')
attempt === 8 ||
!isRetryableNetworkError(error)
) {
throw error;
}
Expand All @@ -21,3 +25,19 @@ export async function gotoWithTlsRetry(

return null;
}

export async function reloadWithNetworkRetry(page: Page): Promise<Response | null> {
for (let attempt = 1; attempt <= 8; attempt += 1) {
try {
return await page.reload();
} catch (error) {
if (attempt === 8 || !isRetryableNetworkError(error)) {
throw error;
}

await page.waitForTimeout(attempt * 1_000);
}
}

return null;
}
13 changes: 8 additions & 5 deletions tests/E2E/update-feedback.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { execFileSync } from 'node:child_process';
import { resolve } from 'node:path';
import AxeBuilder from '@axe-core/playwright';
import { expect, test } from '@playwright/test';
import { gotoWithTlsRetry } from './support/navigation';
import {
gotoWithTlsRetry,
reloadWithNetworkRetry,
} from './support/navigation';

const project = process.env.NETKEEP_E2E_PROJECT ?? 'netkeep-e2e';
const root = resolve(import.meta.dirname, '../..');
Expand Down Expand Up @@ -94,7 +97,7 @@ test('reauthenticates once and preserves update feedback across navigation and r
await expect(
page.getByText('Update request received', { exact: true }),
).toBeVisible();
await page.reload();
await reloadWithNetworkRetry(page);
await expect(
page.getByText('Update request received', { exact: true }),
).toBeVisible();
Expand All @@ -117,7 +120,7 @@ test('reauthenticates once and preserves update feedback across navigation and r
{ timeout: 120_000 },
)
.toBe(200);
await page.reload();
await reloadWithNetworkRetry(page);
await expect(
page.getByText('Updating v1.0.3 to v1.0.6', { exact: true }),
).toBeVisible();
Expand All @@ -132,13 +135,13 @@ test('reauthenticates once and preserves update feedback across navigation and r
"last_progress_at" => now(),
]);
`);
await page.reload();
await reloadWithNetworkRetry(page);
await expect(
page.getByText('NetKeep v1.0.6 was installed successfully.', {
exact: true,
}),
).toBeVisible();
await page.reload();
await reloadWithNetworkRetry(page);
await expect(
page.getByText('NetKeep v1.0.6 was installed successfully.', {
exact: true,
Expand Down
Loading