From fd35d4b688045a53dc95565b0bac06ff3b06cdbb Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 14 Oct 2024 11:43:39 +0200 Subject: [PATCH] WIP --- cli/js/40_test.js | 50 +++++++++++++++++++++++++++++++++++++++++++ cli/tools/test/mod.rs | 2 ++ 2 files changed, 52 insertions(+) diff --git a/cli/js/40_test.js b/cli/js/40_test.js index b4b5144c1b..e3cd49e868 100644 --- a/cli/js/40_test.js +++ b/cli/js/40_test.js @@ -962,6 +962,56 @@ globalThis.afterEach = afterEach; globalThis.it = it; globalThis.describe = describe; +/** + * @param {number} seed + */ +function prepareTests(seed) { + const hasOnly = BDD_CONTEXT.hasOnly; + + if (hasOnly) { + ROOT_TEST_GROUP.only = ROOT_TEST_GROUP.children.some((child) => child.only); + } + + const stack = [ROOT_TEST_GROUP]; + /** @type {TestGroup | undefined} */ + let group; + // deno-lint-ignore no-extra-boolean-cast + while (!!(group = stack.pop())) { + if (hasOnly && !group.only) { + group.ignore = true; + } + + if (seed > 0 && !group.ignore && group.children.length > 1) { + shuffle(group.children, seed); + } + + // Sort tests: + // - non-ignored tests first (might be shuffled earlier) + // - ignored tests second + // - groups last + group.children.sort(sortTestItems); + + for (let i = 0; i < group.children.length; i++) { + const child = group.children[i]; + + if (group.ignore) { + child.ignore = true; + } + + if (isTestGroup(child)) { + stack.push(child); + } + } + } +} + +/** + * @param {*} seed + * @param {*} group + */ +function prepareGroup(seed, group) { +} + /** * This function is called from Rust. * @param {number} seed diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index ff9d99489c..bdb75ce2ea 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -855,6 +855,8 @@ pub async fn run_tests_for_worker( .js_runtime .with_event_loop_promise(call, PollEventLoopOptions::default()) .await; + + _ = send_test_event(&state_rc, TestEvent::Completed); return Ok(()); }