From af901cb892a5ecd493915e49c04dfbecf00c8b0e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Nov 2016 03:37:35 +0100 Subject: [PATCH] improve error handling intest harness --- testlib/selenium/runtime.js | 1 - testlib/talertest.ts | 25 ++++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/testlib/selenium/runtime.js b/testlib/selenium/runtime.js index 84660c35b..e00671175 100644 --- a/testlib/selenium/runtime.js +++ b/testlib/selenium/runtime.js @@ -102,7 +102,6 @@ var script = ` }) .catch((e) => { window.__test_over = true; - console.error(e) }); }) .catch((e) => { diff --git a/testlib/talertest.ts b/testlib/talertest.ts index b602fca14..b28e2036c 100644 --- a/testlib/talertest.ts +++ b/testlib/talertest.ts @@ -57,8 +57,9 @@ export async function run(statusCallback?: (m: string) => void) { let p = new Promise((resolve, reject) => { let pass = (msg?: string) => { if (passed) { - reject(Error("called pass twice")); - return; + let e = Error("test passed twice"); + reject(e); + throw e; } passed = true; lastMsg = msg; @@ -66,14 +67,15 @@ export async function run(statusCallback?: (m: string) => void) { }; let fail = (msg?: string) => { lastMsg = msg; - reject(); - throw Error("test failed"); + let e = Error("test failed"); + reject(e); + throw e; }; let assert = (v: any, msg?: string) => { if (!v) { lastMsg = msg; - reject(); - throw Error("test failed"); + reject(Error("test failed")); + return; } }; let assertEqualsStrict = (v1: any, v2: any, msg?: string) => { @@ -81,8 +83,9 @@ export async function run(statusCallback?: (m: string) => void) { console.log(`# expected: ${v1}`); console.log(`# actual: ${v2}`); lastMsg = msg; - reject(); - throw Error("test failed"); + let e = Error("test failed"); + reject(e); + throw e; } }; // Test might return a promise. If so, wait for it. @@ -105,7 +108,11 @@ export async function run(statusCallback?: (m: string) => void) { console.log(`ok ${Number(i) + 1} ${lastMsg || "-"}`); statusCallback && statusCallback(`finished test ${t.name}`); } catch (e) { - console.error(e); + try { + console.error(e.stack); + } catch (e2) { + console.error(e); + } console.log(`not ok ${Number(i) + 1} ${lastMsg || "-"}`); statusCallback && statusCallback(`failed test ${t.name}`); }