summaryrefslogtreecommitdiff
path: root/runtime/js/40_testing.js
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-07-15 03:05:16 +0800
committerGitHub <noreply@github.com>2021-07-14 21:05:16 +0200
commit69ca44d8e229255760740432ba5d2f95860a66bb (patch)
treee96aa12f4ca9f622d9e457d421de6ab1e1313461 /runtime/js/40_testing.js
parent6ce2a089a89e1e1f844a6cd2bd8eb7a1980bea8f (diff)
refactor(cli/tools/test_runner): split reporter into distinct stages (#11395)
This splits up the reporter into smaller functions, one for each distinct event that happens during the testing process.
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r--runtime/js/40_testing.js53
1 files changed, 28 insertions, 25 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js
index 0d4c23120..617df22d4 100644
--- a/runtime/js/40_testing.js
+++ b/runtime/js/40_testing.js
@@ -186,10 +186,6 @@ finishing test case.`;
ArrayPrototypePush(tests, testDef);
}
- function postTestMessage(kind, data) {
- return core.opSync("op_post_test_message", { message: { kind, data } });
- }
-
function createTestFilter(filter) {
return (def) => {
if (filter) {
@@ -223,25 +219,38 @@ finishing test case.`;
}
}
+ function getTestOrigin() {
+ return core.opSync("op_get_test_origin");
+ }
+
+ function dispatchTestEvent(event) {
+ return core.opSync("op_dispatch_test_event", event);
+ }
+
async function runTests({
disableLog = false,
filter = null,
shuffle = null,
} = {}) {
+ const origin = getTestOrigin();
const originalConsole = globalThis.console;
if (disableLog) {
globalThis.console = new Console(() => {});
}
const only = ArrayPrototypeFilter(tests, (test) => test.only);
- const pending = ArrayPrototypeFilter(
+ const filtered = ArrayPrototypeFilter(
(only.length > 0 ? only : tests),
createTestFilter(filter),
);
- postTestMessage("plan", {
- filtered: tests.length - pending.length,
- pending: pending.length,
- only: only.length > 0,
+
+ dispatchTestEvent({
+ plan: {
+ origin,
+ total: filtered.length,
+ filteredOut: tests.length - filtered.length,
+ usedOnly: only.length > 0,
+ },
});
if (shuffle !== null) {
@@ -256,31 +265,25 @@ finishing test case.`;
};
}(shuffle));
- for (let i = pending.length - 1; i > 0; i--) {
+ for (let i = filtered.length - 1; i > 0; i--) {
const j = nextInt(i);
- [pending[i], pending[j]] = [pending[j], pending[i]];
+ [filtered[i], filtered[j]] = [filtered[j], filtered[i]];
}
}
- for (const test of pending) {
- const {
- name,
- } = test;
-
+ for (const test of filtered) {
+ const description = {
+ origin,
+ name: test.name,
+ };
const earlier = DateNow();
- postTestMessage("wait", {
- name,
- });
+ dispatchTestEvent({ wait: description });
const result = await runTest(test);
- const duration = DateNow() - earlier;
+ const elapsed = DateNow() - earlier;
- postTestMessage("result", {
- name,
- result,
- duration,
- });
+ dispatchTestEvent({ result: [description, result, elapsed] });
}
if (disableLog) {