fix(playwright): raise any pageerror, purpose is to stops immediatly on a bundle issue

This commit is contained in:
Edouard Vanbelle
2026-05-28 01:39:14 +02:00
parent 42cb3627a8
commit ec43c4f9c9
3 changed files with 31 additions and 6 deletions
@@ -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('/');
@@ -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');
+27 -2
View File
@@ -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<object>({
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();