diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-08 16:52:03 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-08 16:52:03 +0100 |
commit | 5dfa8d79e1ec28093056e5f52529ee3103361534 (patch) | |
tree | 9166aa62eeb54ed87f9d754b6ad750ce05f2b6a1 /testlib/talertest.ts | |
parent | afb9fba64be1f15a3ce3ed31214a704e73e5e8bb (diff) | |
download | wallet-core-5dfa8d79e1ec28093056e5f52529ee3103361534.tar.xz |
fixes to test harness
Diffstat (limited to 'testlib/talertest.ts')
-rw-r--r-- | testlib/talertest.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/testlib/talertest.ts b/testlib/talertest.ts index 14074620b..16d8ec14e 100644 --- a/testlib/talertest.ts +++ b/testlib/talertest.ts @@ -19,7 +19,7 @@ * @author Florian Dold */ -type TestFn = (t: TestLib) => void; +type TestFn = (t: TestLib) => void | Promise<void>; interface Test { name: string; @@ -51,9 +51,15 @@ export async function run() { console.log(`1..${tests.length}`); for (let i in tests) { let t = tests[i]; + let passed = false; let lastMsg: string|undefined = undefined; let p = new Promise((resolve, reject) => { let pass = (msg?: string) => { + if (passed) { + reject(Error("called pass twice")); + return; + } + passed = true; lastMsg = msg; resolve(); }; @@ -69,7 +75,9 @@ export async function run() { throw Error("test failed"); } }; - t.testFn({pass,fail, assert}); + // Test might return a promise. If so, wait for it. + let r = t.testFn({pass,fail, assert}); + r.then(() => resolve(), (e) => reject(e)); }); console.log(`# ${t.name}`); @@ -80,6 +88,9 @@ export async function run() { try { await p; + if (passed) { + throw Error("test did not call 'pass'"); + } console.log(`ok ${Number(i) + 1} ${lastMsg}`); } catch (e) { console.error(e); |