From 4a36f9b47014748b6ab68a8d5388d0fb829c72d6 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 11 Mar 2022 10:00:22 -0700 Subject: [PATCH] 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 --- test/end-to-end-tests/src/session.ts | 2 +- test/end-to-end-tests/src/util.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/end-to-end-tests/src/session.ts b/test/end-to-end-tests/src/session.ts index 84f22c4b0c..26590594ee 100644 --- a/test/end-to-end-tests/src/session.ts +++ b/test/end-to-end-tests/src/session.ts @@ -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() ?? ''} ${req.method()} ${req.url()} \n`; }); this.log = new Logger(this.username); } diff --git a/test/end-to-end-tests/src/util.ts b/test/end-to-end-tests/src/util.ts index 1c4e78933a..3b31de2d1e 100644 --- a/test/end-to-end-tests/src/util.ts +++ b/test/end-to-end-tests/src/util.ts @@ -84,7 +84,8 @@ export async function serializeLog(msg: ConsoleMessage): Promise { // 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.