From ed8087683996854285410f1243e1b0c326ebc984 Mon Sep 17 00:00:00 2001 From: ealush Date: Sat, 20 Jul 2024 00:59:26 +0300 Subject: [PATCH] Reduce the number of times hasPending checks happen on test run --- packages/vest/src/core/VestBus/VestBus.ts | 29 ++++++++++++------- .../vestjs-runtime/src/Isolate/Isolate.ts | 1 + packages/vestjs-runtime/src/RuntimeEvents.ts | 3 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/vest/src/core/VestBus/VestBus.ts b/packages/vest/src/core/VestBus/VestBus.ts index 704ce8d8d..04e8ec5b3 100644 --- a/packages/vest/src/core/VestBus/VestBus.ts +++ b/packages/vest/src/core/VestBus/VestBus.ts @@ -2,7 +2,7 @@ import { CB, ValueOf } from 'vest-utils'; import { Bus, RuntimeEvents, TIsolate } from 'vestjs-runtime'; import { Events } from 'BusEvents'; -import { TIsolateTest } from 'IsolateTest'; +// import { TIsolateTest } from 'IsolateTest'; import { useExpireSuiteResultCache, useResetCallbacks, @@ -22,15 +22,7 @@ export function useInitVestBus() { // Report a the completion of a test. There may be other tests with the same // name that are still running, or not yet started. - on(Events.TEST_COMPLETED, (testObject: TIsolateTest) => { - if (VestTest.isCanceled(testObject)) { - return; - } - - const { fieldName } = VestTest.getData(testObject); - - useRunFieldCallbacks(fieldName); - }); + on(Events.TEST_COMPLETED, () => {}); on(Events.TEST_RUN_STARTED, () => { /* Let's just invalidate the suite cache for now */ @@ -50,9 +42,19 @@ export function useInitVestBus() { } VestIsolate.setDone(isolate); + }); + + on(RuntimeEvents.ASYNC_ISOLATE_DONE, (isolate: TIsolate) => { + if (VestTest.is(isolate)) { + if (!VestTest.isCanceled(isolate)) { + const { fieldName } = VestTest.getData(isolate); + + useRunFieldCallbacks(fieldName); + } + } if (!SuiteWalker.hasPending()) { - // When no more tests are running, emit the done event + // When no more async tests are running, emit the done event VestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED); } }); @@ -82,6 +84,11 @@ export function useInitVestBus() { }); on(Events.SUITE_CALLBACK_RUN_FINISHED, () => { + if (!SuiteWalker.hasPending()) { + // When no more async tests are running, emit the done event + VestBus.emit(Events.ALL_RUNNING_TESTS_FINISHED); + } + useOmitOptionalFields(); }); diff --git a/packages/vestjs-runtime/src/Isolate/Isolate.ts b/packages/vestjs-runtime/src/Isolate/Isolate.ts index b3c6bf669..2ec4874d8 100644 --- a/packages/vestjs-runtime/src/Isolate/Isolate.ts +++ b/packages/vestjs-runtime/src/Isolate/Isolate.ts @@ -100,6 +100,7 @@ function useRunAsNew( } emit(RuntimeEvents.ISOLATE_DONE, current); + emit(RuntimeEvents.ASYNC_ISOLATE_DONE, current); }); } else { emit(RuntimeEvents.ISOLATE_DONE, current); diff --git a/packages/vestjs-runtime/src/RuntimeEvents.ts b/packages/vestjs-runtime/src/RuntimeEvents.ts index 90e8150c1..8de49c837 100644 --- a/packages/vestjs-runtime/src/RuntimeEvents.ts +++ b/packages/vestjs-runtime/src/RuntimeEvents.ts @@ -1,5 +1,6 @@ export const RuntimeEvents = { + ASYNC_ISOLATE_DONE: 'ASYNC_ISOLATE_DONE', + ISOLATE_DONE: 'ISOLATE_DONE', ISOLATE_ENTER: 'ISOLATE_ENTER', ISOLATE_PENDING: 'ISOLATE_PENDING', - ISOLATE_DONE: 'ISOLATE_DONE', };