mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 12:06:57 +02:00
fix: resolve flaky offline sync e2e test in CI
Playwright's setOffline(false) doesn't reliably emit the browser's 'online' DOM event in headless/CI environments. Manually dispatch it as a safety net so the sync client always triggers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
8108e62cf1
commit
990639d804
@@ -180,6 +180,7 @@ Write tests first or alongside features. Tests serve as living documentation of
|
|||||||
- Test database: `./data/test-crumbs.db` (cleaned via `global-setup.ts`)
|
- Test database: `./data/test-crumbs.db` (cleaned via `global-setup.ts`)
|
||||||
- Auth fixture: `tests/e2e/helpers/fixtures.ts` provides `authenticatedPage` (handles setup/login race conditions across parallel workers)
|
- Auth fixture: `tests/e2e/helpers/fixtures.ts` provides `authenticatedPage` (handles setup/login race conditions across parallel workers)
|
||||||
- Auth tests use `test.describe.serial` because they depend on sequential database state
|
- Auth tests use `test.describe.serial` because they depend on sequential database state
|
||||||
|
- **Offline/online tests**: After `setOffline(false)`, always manually dispatch the `online` event via `page.evaluate(() => window.dispatchEvent(new Event('online')))` — Playwright doesn't reliably emit it in headless/CI environments, causing flaky `waitForResponse` timeouts
|
||||||
|
|
||||||
### Gherkin-style Given/When/Then
|
### Gherkin-style Given/When/Then
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,11 @@ test.describe('Offline Support', () => {
|
|||||||
await expect(page.getByText('Survive Reload')).toBeVisible();
|
await expect(page.getByText('Survive Reload')).toBeVisible();
|
||||||
|
|
||||||
// When the network is restored and sync completes
|
// When the network is restored and sync completes
|
||||||
const syncResponse = page.waitForResponse('**/api/sync');
|
const syncResponse = page.waitForResponse((resp) => resp.url().includes('/api/sync'));
|
||||||
await page.context().setOffline(false);
|
await page.context().setOffline(false);
|
||||||
|
// Manually dispatch the online event as a safety net — in CI/headless
|
||||||
|
// environments, setOffline(false) doesn't always emit it reliably
|
||||||
|
await page.evaluate(() => window.dispatchEvent(new Event('online')));
|
||||||
await syncResponse;
|
await syncResponse;
|
||||||
|
|
||||||
// And the user reloads the page
|
// And the user reloads the page
|
||||||
|
|||||||
Reference in New Issue
Block a user