tests cleanup
This commit is contained in:
55
tests/shared/website/ConsoleErrorCapture.ts
Normal file
55
tests/shared/website/ConsoleErrorCapture.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { Page } from '@playwright/test';
|
||||
|
||||
export interface CapturedError {
|
||||
type: 'console' | 'page';
|
||||
message: string;
|
||||
stack?: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
|
||||
export class ConsoleErrorCapture {
|
||||
private errors: CapturedError[] = [];
|
||||
|
||||
constructor(private page: Page) {
|
||||
this.setupCapture();
|
||||
}
|
||||
|
||||
private setupCapture(): void {
|
||||
this.page.on('console', (msg) => {
|
||||
if (msg.type() === 'error') {
|
||||
this.errors.push({
|
||||
type: 'console',
|
||||
message: msg.text(),
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.page.on('pageerror', (error) => {
|
||||
this.errors.push({
|
||||
type: 'page',
|
||||
message: error.message,
|
||||
stack: error.stack ?? '',
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public getErrors(): CapturedError[] {
|
||||
return this.errors;
|
||||
}
|
||||
|
||||
public hasErrors(): boolean {
|
||||
return this.errors.length > 0;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this.errors = [];
|
||||
}
|
||||
|
||||
public async waitForErrors(timeout: number = 1000): Promise<boolean> {
|
||||
await this.page.waitForTimeout(timeout);
|
||||
return this.hasErrors();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user