Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4a36f9b

Browse files
authored
Fix logging in end-to-end tests (#8028)
* Nullcheck the argument being stringified * Improve null handling of responses in requestfinished Apparently puppeteer can race on this
1 parent df6c53f commit 4a36f9b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

test/end-to-end-tests/src/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class ElementSession {
4040
"requestfinished", async (req: puppeteer.HTTPRequest) => {
4141
const type = req.resourceType();
4242
const response = await req.response();
43-
return `${type} ${response.status()} ${req.method()} ${req.url()} \n`;
43+
return `${type} ${response?.status() ?? '<no response>'} ${req.method()} ${req.url()} \n`;
4444
});
4545
this.log = new Logger(this.username);
4646
}

test/end-to-end-tests/src/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export async function serializeLog(msg: ConsoleMessage): Promise<string> {
8484
// Note: we have to run the checks against the object in the page context, so call
8585
// evaluate instead of just doing it ourselves.
8686
const stringyArg: string = await arg.evaluate((argInContext: any) => {
87-
if (argInContext.stack || (argInContext instanceof Error)) {
87+
// sometimes the argument will be `null` or similar - treat it safely.
88+
if (argInContext?.stack || (argInContext instanceof Error)) {
8889
// probably an error - toString it and append any properties which might not be
8990
// caught. For example, on HTTP errors the JSON stringification will capture the
9091
// status code.

0 commit comments

Comments
 (0)