diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-07-05 16:26:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 10:26:57 +0200 |
commit | c4cc353d594edae121fd1e8fcd5c85d4ae0d0988 (patch) | |
tree | 3802b914ded534810ecd2bffb38113610fba6dc9 /runtime/js/40_testing.js | |
parent | 6a4769670df5ea3653a110474af0ec2ca79eeb0b (diff) |
refactor(runtime): reduce duplication in test harness (#11274)
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r-- | runtime/js/40_testing.js | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index b1adfa993..3107f70a1 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -191,48 +191,23 @@ finishing test case.`; core.opSync("op_restore_test_permissions", token); } - async function runTest({ name, ignore, fn, permissions }) { + async function runTest({ ignore, fn, permissions }) { let token = null; - const time = DateNow(); try { - postTestMessage("wait", { - name, - }); - if (permissions) { token = pledgeTestPermissions(permissions); } if (ignore) { - const duration = DateNow() - time; - postTestMessage("result", { - name, - duration, - result: "ignored", - }); - - return; + return "ignored"; } await fn(); - const duration = DateNow() - time; - postTestMessage("result", { - name, - duration, - result: "ok", - }); + return "ok"; } catch (error) { - const duration = DateNow() - time; - - postTestMessage("result", { - name, - duration, - result: { - "failed": inspectArgs([error]), - }, - }); + return { "failed": inspectArgs([error]) }; } finally { if (token) { restoreTestPermissions(token); @@ -261,7 +236,24 @@ finishing test case.`; }); for (const test of pending) { - await runTest(test); + const { + name, + } = test; + + const earlier = DateNow(); + + postTestMessage("wait", { + name, + }); + + const result = await runTest(test); + const duration = DateNow() - earlier; + + postTestMessage("result", { + name, + result, + duration, + }); } if (disableLog) { |