Extend E2E assertions
This commit is contained in:
parent
904a2737d4
commit
e8c57b3a37
2 changed files with 532 additions and 239 deletions
25
frontend/test-client/src/utils/test-error-tracker.ts
Normal file
25
frontend/test-client/src/utils/test-error-tracker.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
export class TestErrorTracker {
|
||||
private firstError: { agentName: string; message: string } | null = null;
|
||||
|
||||
public recordError(agentName: string, message: string): void {
|
||||
this.firstError ??= { agentName, message };
|
||||
}
|
||||
|
||||
/**
|
||||
* If an error was recorded, throw it. Call this at natural checkpoints:
|
||||
* after each iteration, before assertions, etc.
|
||||
*/
|
||||
public checkAndThrow(): void {
|
||||
if (this.firstError !== null) {
|
||||
const { agentName, message } = this.firstError;
|
||||
throw new Error(
|
||||
`ERROR-level log from ${agentName}: ${message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** Clear recorded errors. Call at the start of each test. */
|
||||
public reset(): void {
|
||||
this.firstError = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,10 @@
|
|||
export class TimeoutError extends Error {
|
||||
public constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "TimeoutError";
|
||||
}
|
||||
}
|
||||
|
||||
export async function withTimeout<T>(
|
||||
promise: Promise<T>,
|
||||
timeoutMs: number,
|
||||
|
|
@ -8,7 +15,9 @@ export async function withTimeout<T>(
|
|||
new Promise<T>((_, reject) =>
|
||||
setTimeout(() => {
|
||||
reject(
|
||||
new Error(`${operationName} timed out after ${timeoutMs}ms`)
|
||||
new TimeoutError(
|
||||
`${operationName} timed out after ${timeoutMs}ms`
|
||||
)
|
||||
);
|
||||
}, timeoutMs)
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue