improve error handling intest harness

This commit is contained in:
Florian Dold 2016-11-14 03:37:35 +01:00
parent 8fdbfeea59
commit af901cb892
2 changed files with 16 additions and 10 deletions

View File

@ -102,7 +102,6 @@ var script = `
}) })
.catch((e) => { .catch((e) => {
window.__test_over = true; window.__test_over = true;
console.error(e)
}); });
}) })
.catch((e) => { .catch((e) => {

View File

@ -57,8 +57,9 @@ export async function run(statusCallback?: (m: string) => void) {
let p = new Promise((resolve, reject) => { let p = new Promise((resolve, reject) => {
let pass = (msg?: string) => { let pass = (msg?: string) => {
if (passed) { if (passed) {
reject(Error("called pass twice")); let e = Error("test passed twice");
return; reject(e);
throw e;
} }
passed = true; passed = true;
lastMsg = msg; lastMsg = msg;
@ -66,14 +67,15 @@ export async function run(statusCallback?: (m: string) => void) {
}; };
let fail = (msg?: string) => { let fail = (msg?: string) => {
lastMsg = msg; lastMsg = msg;
reject(); let e = Error("test failed");
throw Error("test failed"); reject(e);
throw e;
}; };
let assert = (v: any, msg?: string) => { let assert = (v: any, msg?: string) => {
if (!v) { if (!v) {
lastMsg = msg; lastMsg = msg;
reject(); reject(Error("test failed"));
throw Error("test failed"); return;
} }
}; };
let assertEqualsStrict = (v1: any, v2: any, msg?: string) => { 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(`# expected: ${v1}`);
console.log(`# actual: ${v2}`); console.log(`# actual: ${v2}`);
lastMsg = msg; lastMsg = msg;
reject(); let e = Error("test failed");
throw Error("test failed"); reject(e);
throw e;
} }
}; };
// Test might return a promise. If so, wait for it. // 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 || "-"}`); console.log(`ok ${Number(i) + 1} ${lastMsg || "-"}`);
statusCallback && statusCallback(`finished test ${t.name}`); statusCallback && statusCallback(`finished test ${t.name}`);
} catch (e) { } catch (e) {
console.error(e); try {
console.error(e.stack);
} catch (e2) {
console.error(e);
}
console.log(`not ok ${Number(i) + 1} ${lastMsg || "-"}`); console.log(`not ok ${Number(i) + 1} ${lastMsg || "-"}`);
statusCallback && statusCallback(`failed test ${t.name}`); statusCallback && statusCallback(`failed test ${t.name}`);
} }