diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-09-06 04:42:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-05 22:42:35 +0200 |
commit | 01bfb7d9138ebd31ee5f8502786bcb9be7ed6f69 (patch) | |
tree | 3d5c72b7cfe84bf139f7e268193082ccd87f8362 /runtime/js/40_testing.js | |
parent | bb99d5da4c9d7d17e08097d004bf36f0976a678c (diff) |
refactor(testing): use discrete report functions (#11917)
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r-- | runtime/js/40_testing.js | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 4e7c231b2..38382f9fd 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -223,8 +223,28 @@ finishing test case.`; return core.opSync("op_get_test_origin"); } - function dispatchTestEvent(event) { - return core.opSync("op_dispatch_test_event", event); + function reportTestPlan(plan) { + core.opSync("op_dispatch_test_event", { + plan, + }); + } + + function reportTestConsoleOutput(console) { + core.opSync("op_dispatch_test_event", { + output: { console }, + }); + } + + function reportTestWait(test) { + core.opSync("op_dispatch_test_event", { + wait: test, + }); + } + + function reportTestResult(test, result, elapsed) { + core.opSync("op_dispatch_test_event", { + result: [test, result, elapsed], + }); } async function runTests({ @@ -234,13 +254,7 @@ finishing test case.`; const origin = getTestOrigin(); const originalConsole = globalThis.console; - globalThis.console = new Console((line) => { - dispatchTestEvent({ - output: { - console: line, - }, - }); - }); + globalThis.console = new Console(reportTestConsoleOutput); const only = ArrayPrototypeFilter(tests, (test) => test.only); const filtered = ArrayPrototypeFilter( @@ -248,13 +262,11 @@ finishing test case.`; createTestFilter(filter), ); - dispatchTestEvent({ - plan: { - origin, - total: filtered.length, - filteredOut: tests.length - filtered.length, - usedOnly: only.length > 0, - }, + reportTestPlan({ + origin, + total: filtered.length, + filteredOut: tests.length - filtered.length, + usedOnly: only.length > 0, }); if (shuffle !== null) { @@ -282,12 +294,12 @@ finishing test case.`; }; const earlier = DateNow(); - dispatchTestEvent({ wait: description }); + reportTestWait(description); const result = await runTest(test); const elapsed = DateNow() - earlier; - dispatchTestEvent({ result: [description, result, elapsed] }); + reportTestResult(description, result, elapsed); } globalThis.console = originalConsole; |