summaryrefslogtreecommitdiff
path: root/runtime/js/40_testing.js
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r--runtime/js/40_testing.js48
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;