From afcbdc632cfca398ba7c5837a402b2773772bd64 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Tue, 9 Jun 2020 18:34:09 -0700 Subject: [PATCH] Fix log printing on Safari/Firefox (#214) Thought I tested this, but error.stack does not contain the error message on Safari and Firefox. So include it explicitly when printing. --- src/common/framework/logging/log_message.ts | 8 +++----- src/unittests/loaders_and_trees.spec.ts | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/common/framework/logging/log_message.ts b/src/common/framework/logging/log_message.ts index 5c5c0900357b..9803c2752268 100644 --- a/src/common/framework/logging/log_message.ts +++ b/src/common/framework/logging/log_message.ts @@ -22,12 +22,10 @@ export class LogMessageWithStack extends Error { } toJSON(): string { - let m = this.name + ': '; + let m = this.name; + if (this.message) m += ': ' + this.message; if (!this.stackHidden && this.stack) { - // this.message is already included in this.stack - m += extractImportantStackTrace(this); - } else { - m += this.message; + m += '\n' + extractImportantStackTrace(this); } if (this.timesSeen > 1) { m += `\n(seen ${this.timesSeen} times with identical stack)`; diff --git a/src/unittests/loaders_and_trees.spec.ts b/src/unittests/loaders_and_trees.spec.ts index 5ca7e7e5d3b2..70df2c0f7337 100644 --- a/src/unittests/loaders_and_trees.spec.ts +++ b/src/unittests/loaders_and_trees.spec.ts @@ -91,7 +91,7 @@ const specsData: { [k: string]: SpecFile } = { t.debug('OK'); }); g.test('bluh,a').fn(t => { - t.fail('bye'); + t.fail('goodbye'); }); return g; })(), @@ -223,7 +223,7 @@ g.test('end2end').fn(async t => { t.expect(log.results.get(name) === res); t.expect(res.status === status); - t.expect(res.timems > 0); + t.expect(res.timems >= 0); assert(res.logs !== undefined); // only undefined while pending t.expect(logs(res.logs.map(l => JSON.stringify(l)))); }; @@ -240,7 +240,7 @@ g.test('end2end').fn(async t => { 'fail', logs => logs.length === 1 && - logs[0].startsWith('"EXPECTATION FAILED: Error: bye\\n') && + logs[0].startsWith('"EXPECTATION FAILED: goodbye\\n') && logs[0].indexOf('loaders_and_trees.spec.') !== -1 ); });