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

Commit

Permalink
Fix logging in end-to-end tests (#8028)
Browse files Browse the repository at this point in the history
* Nullcheck the argument being stringified

* Improve null handling of responses in requestfinished

Apparently puppeteer can race on this
  • Loading branch information
turt2live authored Mar 11, 2022
1 parent df6c53f commit 4a36f9b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/end-to-end-tests/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ElementSession {
"requestfinished", async (req: puppeteer.HTTPRequest) => {
const type = req.resourceType();
const response = await req.response();
return `${type} ${response.status()} ${req.method()} ${req.url()} \n`;
return `${type} ${response?.status() ?? '<no response>'} ${req.method()} ${req.url()} \n`;
});
this.log = new Logger(this.username);
}
Expand Down
3 changes: 2 additions & 1 deletion test/end-to-end-tests/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export async function serializeLog(msg: ConsoleMessage): Promise<string> {
// Note: we have to run the checks against the object in the page context, so call
// evaluate instead of just doing it ourselves.
const stringyArg: string = await arg.evaluate((argInContext: any) => {
if (argInContext.stack || (argInContext instanceof Error)) {
// sometimes the argument will be `null` or similar - treat it safely.
if (argInContext?.stack || (argInContext instanceof Error)) {
// probably an error - toString it and append any properties which might not be
// caught. For example, on HTTP errors the JSON stringification will capture the
// status code.
Expand Down

0 comments on commit 4a36f9b

Please sign in to comment.