super-productivity/e2e/fixtures/webdav.fixture.ts
Johannes Millan 77f83c5687
test(e2e): harden failure signals and provider gates (#7753)
* test: harden e2e failure signals

Fail otherwise-passing E2E tests on browser runtime errors, keep Playwright retries disabled, preserve Docker E2E exit codes, and make plugin/WebDAV setup failures hard failures instead of logged or skipped conditions.

* test: harden provider e2e runners

Make WebDAV and SuperSync runner scripts require provider readiness, preserve cleanup and argument forwarding, and fail manual sync clients on uncaught page errors.

* ci: require providers for scheduled e2e

Set required-provider flags in scheduled WebDAV and SuperSync jobs, and remove the duplicate provider runner scripts while keeping local npm aliases inline.

* test: catch e2e teardown pageerrors and tighten fixture

- closeClient now asserts runtime errors AFTER context.close() so
  pageerrors emitted during teardown (Angular destroy hooks, late RxJS
  errors) are captured instead of dropped. Matches the pattern in
  guardContextCloseWithRuntimeErrorCheck.
- test.fixture.ts isolatedContext now spreads Playwright's merged
  contextOptions instead of destructuring 23 fields by hand. Future
  option additions propagate automatically; the page fixture uses the
  shared attachPageErrorCollector and only fails on pageerror (not
  console.error, which is too noisy). Guards against a configured 0
  timeout being treated as undefined.
- plugin-loading.spec.ts second test now hard-asserts that the plugin
  menu entry reappears after re-enable, matching the first test instead
  of silently logging when not visible.

* test(sync): stabilize ImmediateUploadService spec

Two complementary fixes for flaky failures observed under full-suite
random-order runs where the upload pipeline silently never fires:

- Pin navigator.onLine = true in beforeEach (restored in afterEach).
  isOnline() inside _canUpload reads navigator.onLine directly. The
  keyboard-layout spec replaces the whole navigator and the is-online
  spec spies on it; if order or restoration ever drifts, every "should
  fire upload" test fails trivially while the "should NOT" tests pass.
- Replace tick(2100) with tick(2000); flush(). The await chain inside
  withSession() (provider.isReady, withSession entry, uploadPendingOps,
  optional LWW re-upload) requires more microtask drain than tick's
  fixed-time window reliably provides under load. flush() drains the
  pipeline regardless.

* test(e2e): guard skipOnboarding init script against data: frames

The new page-error collector started failing plugin specs because
addInitScript runs in every frame — including the empty data:text/html
iframe that plugin-index swaps in on destroy — and localStorage access
in a data: URL throws SecurityError. Wrap the four setItem calls in
try/catch so the helper noops in storage-less frames.
2026-05-23 20:33:04 +02:00

96 lines
2.8 KiB
TypeScript

import { test as base } from '@playwright/test';
import { isWebDavServerUp } from '../utils/check-webdav';
/**
* Extended test fixture for WebDAV E2E tests.
*
* Provides:
* - Automatic server health check (skips tests if server unavailable)
* - Worker-level caching to avoid redundant health checks
*
* This reduces health check overhead from ~8s to ~2s when WebDAV is unavailable
* by checking once per worker instead of once per test file.
*
* Usage:
* ```typescript
* import { test, expect } from '../../fixtures/webdav.fixture';
*
* test.describe('@webdav My Tests', () => {
* test('should sync', async ({ page, request }) => {
* // Server health already checked, test will skip if unavailable
* });
* });
* ```
*/
export interface WebDavFixtures {
/** Whether the WebDAV server is reachable and available */
webdavServerUp: boolean;
}
// Cache server health check result per worker to avoid repeated checks
let serverHealthCache: boolean | null = null;
const requireHealthyWebDav = (isHealthy: boolean, skip: () => void): void => {
if (isHealthy) {
return;
}
if (process.env.E2E_REQUIRE_WEBDAV === 'true') {
throw new Error('WebDAV server is required for this run but is not reachable.');
}
skip();
};
export const test = base.extend<WebDavFixtures>({
/**
* Check WebDAV server health once per worker and cache the result.
* Tests are automatically skipped if the server is not reachable.
*/
webdavServerUp: async ({}, use, testInfo) => {
// Only check once per worker
if (serverHealthCache === null) {
serverHealthCache = await isWebDavServerUp();
if (!serverHealthCache) {
console.warn(
'WebDAV server not reachable at http://127.0.0.1:2345/ - skipping tests',
);
}
}
requireHealthyWebDav(serverHealthCache, () => {
testInfo.skip(true, 'WebDAV server not reachable');
});
await use(serverHealthCache);
},
});
/**
* Helper to create a describe block that auto-checks WebDAV server health.
* Use this instead of manually adding beforeAll health checks.
*
* @param title - Test suite title (will be prefixed with @webdav)
* @param fn - Test suite function
*
* @example
* ```typescript
* webdavDescribe('Archive Sync', () => {
* test('should sync archive', async ({ page, webdavServerUp }) => {
* // Server health already checked
* });
* });
* ```
*/
export const webdavDescribe = (title: string, fn: () => void): void => {
test.describe(`@webdav ${title}`, () => {
// The webdavServerUp fixture will auto-skip if server unavailable
test.beforeEach(async ({ webdavServerUp }) => {
// This line ensures the fixture is evaluated and test is skipped if needed
void webdavServerUp;
});
fn();
});
};
// Re-export expect for convenience
export { expect } from '@playwright/test';