diff --git a/packages/vest/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap b/packages/vest/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap index 2548791fa..2d7b87a96 100644 --- a/packages/vest/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap +++ b/packages/vest/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap @@ -326,3 +326,130 @@ SuiteSummary { "warnings": [], } `; + +exports[`Stateful async tests Merges skipped validations from previous suite 4`] = ` +SuiteSummary { + "errorCount": 5, + "errors": [ + SummaryFailure { + "fieldName": "field_1", + "groupName": "group", + "message": "field_1_group_message", + }, + SummaryFailure { + "fieldName": "field_4", + "groupName": "group", + "message": "field_4_group_message", + }, + SummaryFailure { + "fieldName": "field_1", + "groupName": undefined, + "message": "field_message_1", + }, + SummaryFailure { + "fieldName": "field_2", + "groupName": undefined, + "message": "rejection_message_1", + }, + SummaryFailure { + "fieldName": "field_3", + "groupName": undefined, + "message": "field_message_3", + }, + ], + "getError": [Function], + "getErrors": [Function], + "getErrorsByGroup": [Function], + "getMessage": [Function], + "getWarning": [Function], + "getWarnings": [Function], + "getWarningsByGroup": [Function], + "groups": { + "group": { + "field_1": SummaryBase { + "errorCount": 1, + "errors": [ + "field_1_group_message", + ], + "pendingCount": 0, + "testCount": 1, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "field_4": SummaryBase { + "errorCount": 1, + "errors": [ + "field_4_group_message", + ], + "pendingCount": 0, + "testCount": 1, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + }, + }, + "hasErrors": [Function], + "hasErrorsByGroup": [Function], + "hasWarnings": [Function], + "hasWarningsByGroup": [Function], + "isPending": [Function], + "isTested": [Function], + "isValid": [Function], + "isValidByGroup": [Function], + "pendingCount": 0, + "suiteName": undefined, + "testCount": 7, + "tests": { + "field_1": { + "errorCount": 2, + "errors": [ + "field_1_group_message", + "field_message_1", + ], + "pendingCount": 0, + "testCount": 2, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "field_2": { + "errorCount": 1, + "errors": [ + "rejection_message_1", + ], + "pendingCount": 0, + "testCount": 2, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "field_3": { + "errorCount": 1, + "errors": [ + "field_message_3", + ], + "pendingCount": 0, + "testCount": 2, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + "field_4": SummaryBase { + "errorCount": 1, + "errors": [ + "field_4_group_message", + ], + "pendingCount": 0, + "testCount": 1, + "valid": false, + "warnCount": 0, + "warnings": [], + }, + }, + "valid": false, + "warnCount": 0, + "warnings": [], +} +`; 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', };