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
This commit is contained in:
Travis Ralston 2022-03-11 10:00:22 -07:00 committed by GitHub
parent df6c53ff41
commit 4a36f9b470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -40,7 +40,7 @@ export class ElementSession {
"requestfinished", async (req: puppeteer.HTTPRequest) => { "requestfinished", async (req: puppeteer.HTTPRequest) => {
const type = req.resourceType(); const type = req.resourceType();
const response = await req.response(); 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); this.log = new Logger(this.username);
} }

View file

@ -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 // Note: we have to run the checks against the object in the page context, so call
// evaluate instead of just doing it ourselves. // evaluate instead of just doing it ourselves.
const stringyArg: string = await arg.evaluate((argInContext: any) => { 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 // 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 // caught. For example, on HTTP errors the JSON stringification will capture the
// status code. // status code.