diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-14 03:37:35 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-14 03:37:35 +0100 |
commit | af901cb892a5ecd493915e49c04dfbecf00c8b0e (patch) | |
tree | 2a46692b0384f5141832bd2f7db7fa241df10be4 | |
parent | 8fdbfeea599281d6fa90e7f38009ad94c4d7490e (diff) |
improve error handling intest harness
-rw-r--r-- | testlib/selenium/runtime.js | 1 | ||||
-rw-r--r-- | 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}`); } |