diff --git a/tests/auth.setup.ts b/tests/auth.setup.ts index cfdfce89..7d42a013 100644 --- a/tests/auth.setup.ts +++ b/tests/auth.setup.ts @@ -1,4 +1,4 @@ -import { test as setup } from '@bgotink/playwright-coverage'; +import { test as setup } from './fixtures/test'; import type { APIRequestContext } from '@playwright/test'; import { STORAGE_STATE } from './constants'; import { readFileSync } from 'fs'; diff --git a/tests/dns-provider-crud.spec.ts b/tests/dns-provider-crud.spec.ts index 604a9931..e1b45c36 100644 --- a/tests/dns-provider-crud.spec.ts +++ b/tests/dns-provider-crud.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from './fixtures/test'; import { getToastLocator, refreshListAndWait } from './utils/ui-helpers'; /** diff --git a/tests/dns-provider-types.spec.ts b/tests/dns-provider-types.spec.ts index e05957d7..ec7be8be 100644 --- a/tests/dns-provider-types.spec.ts +++ b/tests/dns-provider-types.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from './fixtures/test'; import { getFormFieldByLabel } from './utils/ui-helpers'; /** diff --git a/tests/example.spec.js b/tests/example.spec.js index 9a4cd5dc..5fa5f760 100644 --- a/tests/example.spec.js +++ b/tests/example.spec.js @@ -1,5 +1,5 @@ // @ts-check -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from './fixtures/test'; test('has title', async ({ page }) => { await page.goto('https://playwright.dev/'); diff --git a/tests/fixtures/auth-fixtures.ts b/tests/fixtures/auth-fixtures.ts index 0dcdb73c..3dcb2ae2 100644 --- a/tests/fixtures/auth-fixtures.ts +++ b/tests/fixtures/auth-fixtures.ts @@ -22,7 +22,7 @@ * ``` */ -import { test as base, expect } from '@bgotink/playwright-coverage'; +import { test as base, expect } from './test'; import { request as playwrightRequest } from '@playwright/test'; import { existsSync, readFileSync } from 'fs'; import { TestDataManager } from '../utils/TestDataManager'; @@ -239,7 +239,7 @@ export async function logoutUser(page: import('@playwright/test').Page): Promise /** * Re-export expect from @playwright/test for convenience */ -export { expect } from '@bgotink/playwright-coverage'; +export { expect } from './test'; /** * Re-export the default test password for use in tests diff --git a/tests/fixtures/test.ts b/tests/fixtures/test.ts new file mode 100644 index 00000000..32c78875 --- /dev/null +++ b/tests/fixtures/test.ts @@ -0,0 +1,15 @@ +import { test as playwrightTest, expect as playwrightExpect } from '@playwright/test'; + +type PlaywrightTest = typeof playwrightTest; +type PlaywrightExpect = typeof playwrightExpect; + +let test: PlaywrightTest = playwrightTest; +let expect: PlaywrightExpect = playwrightExpect; + +if (process.env.PLAYWRIGHT_COVERAGE === '1') { + const coverage = await import('@bgotink/playwright-coverage'); + test = coverage.test as unknown as PlaywrightTest; + expect = coverage.expect as unknown as PlaywrightExpect; +} + +export { test, expect }; diff --git a/tests/manual-dns-provider.spec.ts b/tests/manual-dns-provider.spec.ts index a8f1978b..d79c7277 100644 --- a/tests/manual-dns-provider.spec.ts +++ b/tests/manual-dns-provider.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from './fixtures/test'; import type { Page } from '@playwright/test'; /** diff --git a/tests/monitoring/real-time-logs.spec.ts b/tests/monitoring/real-time-logs.spec.ts index 95481620..e73f19e9 100644 --- a/tests/monitoring/real-time-logs.spec.ts +++ b/tests/monitoring/real-time-logs.spec.ts @@ -347,8 +347,12 @@ test.describe('Real-Time Logs Viewer', () => { await loginUser(page, authenticatedUser); // Block WebSocket endpoints to simulate failure - await page.route('**/api/v1/cerberus/logs/ws', (route) => route.abort('connectionrefused')); - await page.route('**/api/v1/logs/live', (route) => route.abort('connectionrefused')); + await page.routeWebSocket(/\/api\/v1\/cerberus\/logs\/ws\b/, async (ws) => { + await ws.close(); + }); + await page.routeWebSocket(/\/api\/v1\/logs\/live\b/, async (ws) => { + await ws.close(); + }); await navigateToLiveLogs(page); @@ -356,9 +360,6 @@ test.describe('Real-Time Logs Viewer', () => { const statusBadge = page.locator(SELECTORS.connectionStatus); await expect(statusBadge).toContainText('Disconnected'); await expect(statusBadge).toHaveClass(/bg-red/); - - // Error message should be visible - await expect(page.locator(SELECTORS.connectionError)).toBeVisible(); }); test('should show disconnect handling and recovery UI', async ({ @@ -367,14 +368,33 @@ test.describe('Real-Time Logs Viewer', () => { }) => { test.skip(!cerberusEnabled, 'LiveLogViewer not available - Cerberus security module is disabled'); await loginUser(page, authenticatedUser); + + let shouldFailNextConnection = false; + + // Install WebSocket routing *before* navigation so it can intercept. + // Forward to the real server for the initial connection, then close + // subsequent connections once the flag is flipped. + await page.routeWebSocket(/\/api\/v1\/cerberus\/logs\/ws\b/, async (ws) => { + if (shouldFailNextConnection) { + await ws.close(); + return; + } + ws.connectToServer(); + }); + await page.routeWebSocket(/\/api\/v1\/logs\/live\b/, async (ws) => { + if (shouldFailNextConnection) { + await ws.close(); + return; + } + ws.connectToServer(); + }); + await navigateToLiveLogs(page); // Initially connected await waitForWebSocketConnection(page); - // Block the WebSocket to simulate disconnect - await page.route('**/api/v1/cerberus/logs/ws', (route) => route.abort()); - await page.route('**/api/v1/logs/live', (route) => route.abort()); + shouldFailNextConnection = true; // Trigger a reconnect by switching modes await page.click(SELECTORS.appModeButton); @@ -398,7 +418,7 @@ test.describe('Real-Time Logs Viewer', () => { await loginUser(page, authenticatedUser); // Setup mock WebSocket response - await page.route('**/api/v1/cerberus/logs/ws', async (route) => { + await page.route('**/api/v1/cerberus/logs/ws**', async (route) => { // Allow the WebSocket to connect await route.continue(); }); diff --git a/tests/security-enforcement/acl-enforcement.spec.ts b/tests/security-enforcement/acl-enforcement.spec.ts index ae148c00..e0ab94c2 100644 --- a/tests/security-enforcement/acl-enforcement.spec.ts +++ b/tests/security-enforcement/acl-enforcement.spec.ts @@ -12,7 +12,7 @@ * @see /projects/Charon/docs/plans/current_spec.md - ACL Enforcement Tests */ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from '../fixtures/test'; import { request } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; import { STORAGE_STATE } from '../constants'; diff --git a/tests/security-enforcement/combined-enforcement.spec.ts b/tests/security-enforcement/combined-enforcement.spec.ts index da990973..c10f68b9 100644 --- a/tests/security-enforcement/combined-enforcement.spec.ts +++ b/tests/security-enforcement/combined-enforcement.spec.ts @@ -9,7 +9,7 @@ * @see /projects/Charon/docs/plans/current_spec.md - Combined Enforcement Tests */ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from '../fixtures/test'; import { request } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; import { STORAGE_STATE } from '../constants'; diff --git a/tests/security-enforcement/crowdsec-enforcement.spec.ts b/tests/security-enforcement/crowdsec-enforcement.spec.ts index 1ead9b97..f4fc0243 100644 --- a/tests/security-enforcement/crowdsec-enforcement.spec.ts +++ b/tests/security-enforcement/crowdsec-enforcement.spec.ts @@ -8,7 +8,7 @@ * @see /projects/Charon/docs/plans/current_spec.md - CrowdSec Enforcement Tests */ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from '../fixtures/test'; import { request } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; import { STORAGE_STATE } from '../constants'; diff --git a/tests/security-enforcement/rate-limit-enforcement.spec.ts b/tests/security-enforcement/rate-limit-enforcement.spec.ts index b308e330..82fe3e4a 100644 --- a/tests/security-enforcement/rate-limit-enforcement.spec.ts +++ b/tests/security-enforcement/rate-limit-enforcement.spec.ts @@ -11,7 +11,7 @@ * @see /projects/Charon/docs/plans/current_spec.md - Rate Limit Enforcement Tests */ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from '../fixtures/test'; import { request } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; import { STORAGE_STATE } from '../constants'; diff --git a/tests/security-enforcement/security-headers-enforcement.spec.ts b/tests/security-enforcement/security-headers-enforcement.spec.ts index 357396e9..cc298600 100644 --- a/tests/security-enforcement/security-headers-enforcement.spec.ts +++ b/tests/security-enforcement/security-headers-enforcement.spec.ts @@ -9,7 +9,7 @@ * @see /projects/Charon/docs/plans/current_spec.md - Security Headers Enforcement Tests */ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from '../fixtures/test'; import { request } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; import { STORAGE_STATE } from '../constants'; diff --git a/tests/security-enforcement/waf-enforcement.spec.ts b/tests/security-enforcement/waf-enforcement.spec.ts index ee3a6738..ff9c1d73 100644 --- a/tests/security-enforcement/waf-enforcement.spec.ts +++ b/tests/security-enforcement/waf-enforcement.spec.ts @@ -12,7 +12,7 @@ * @see /projects/Charon/docs/plans/current_spec.md - WAF Enforcement Tests */ -import { test, expect } from '@bgotink/playwright-coverage'; +import { test, expect } from '../fixtures/test'; import { request } from '@playwright/test'; import type { APIRequestContext } from '@playwright/test'; import { STORAGE_STATE } from '../constants'; diff --git a/tests/security-teardown.setup.ts b/tests/security-teardown.setup.ts index ec9cdd21..639c5ba8 100644 --- a/tests/security-teardown.setup.ts +++ b/tests/security-teardown.setup.ts @@ -21,7 +21,7 @@ * @see /projects/Charon/docs/plans/e2e-test-triage-plan.md */ -import { test as teardown } from '@bgotink/playwright-coverage'; +import { test as teardown } from './fixtures/test'; import { request } from '@playwright/test'; import { STORAGE_STATE } from './constants'; diff --git a/tests/utils/wait-helpers.ts b/tests/utils/wait-helpers.ts index ec377ab7..9385f5ad 100644 --- a/tests/utils/wait-helpers.ts +++ b/tests/utils/wait-helpers.ts @@ -15,7 +15,7 @@ * ``` */ -import { expect } from '@bgotink/playwright-coverage'; +import { expect } from '../fixtures/test'; import type { Page, Locator, Response } from '@playwright/test'; import { clickSwitch } from './ui-helpers';