From ec43c4f9c96900daa035863a33d80cf5e6565753 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Thu, 28 May 2026 01:39:14 +0200 Subject: [PATCH] fix(playwright): raise any pageerror, purpose is to stops immediatly on a bundle issue --- tests/e2e/scenarios/01-home-and-login.spec.ts | 4 +-- .../scenarios/02-folder-management.spec.ts | 4 +-- tests/e2e/scenarios/helpers.ts | 29 +++++++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/tests/e2e/scenarios/01-home-and-login.spec.ts b/tests/e2e/scenarios/01-home-and-login.spec.ts index 071b7694..6ae2c3c7 100644 --- a/tests/e2e/scenarios/01-home-and-login.spec.ts +++ b/tests/e2e/scenarios/01-home-and-login.spec.ts @@ -1,5 +1,5 @@ -import { test, expect } from '@playwright/test'; -import { goToLoginPage, loginAsAdmin, TEST_ADMIN } from './helpers'; +import { expect } from '@playwright/test'; +import { test, goToLoginPage, loginAsAdmin, TEST_ADMIN } from './helpers'; test('has OxiCloud title', async ({ page }) => { await page.goto('/'); diff --git a/tests/e2e/scenarios/02-folder-management.spec.ts b/tests/e2e/scenarios/02-folder-management.spec.ts index 72dcba5e..d78d2211 100644 --- a/tests/e2e/scenarios/02-folder-management.spec.ts +++ b/tests/e2e/scenarios/02-folder-management.spec.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import * as fs from 'fs/promises'; -import { test, expect, Page } from '@playwright/test'; -import { loginAsAdmin } from './helpers'; +import { expect, Page } from '@playwright/test'; +import { test, loginAsAdmin } from './helpers'; const FIXTURES = path.join(__dirname, '../../fixtures'); diff --git a/tests/e2e/scenarios/helpers.ts b/tests/e2e/scenarios/helpers.ts index 369dbff6..304e6239 100644 --- a/tests/e2e/scenarios/helpers.ts +++ b/tests/e2e/scenarios/helpers.ts @@ -1,4 +1,25 @@ -import { Page, expect } from '@playwright/test'; +import { test as base, Page, expect } from '@playwright/test'; + +/** + * Extended `test` fixture that fails on any unhandled browser-side JavaScript + * error (SyntaxError, ReferenceError, uncaught promise rejections, etc.). + * + * Import `test` from this module instead of `@playwright/test` so every spec + * gets the listener automatically without per-file boilerplate. + */ +export const test = base.extend({ + page: async ({ page }, use) => { + const jsErrors: Error[] = []; + page.on('pageerror', (err) => jsErrors.push(err)); + await use(page); + if (jsErrors.length > 0) { + throw new Error( + `${jsErrors.length} unhandled JS error(s) on page:\n` + + jsErrors.map((e) => ` • ${e.message}`).join('\n') + ); + } + }, +}); export const TEST_ADMIN = { username: 'admin', @@ -38,7 +59,11 @@ export async function goToLoginPage(page: Page) { await page.goto('/'); // Both panels start with .hidden — wait for JS to reveal one. - await page.waitForSelector('#language-panel:not(.hidden), #login-panel:not(.hidden)'); + // Use expect() (5 s default) rather than waitForSelector() (30 s) so a JS + // crash fails fast instead of hanging for the full test timeout. + await expect( + page.locator('#language-panel:not(.hidden), #login-panel:not(.hidden)').first() + ).toBeAttached(); if (await page.locator('#language-panel').isVisible()) { await page.locator('#language-continue').click();