Skip to content

Commit

Permalink
Reduce the number of times hasPending checks happen on test run
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 19, 2024
1 parent 8f74204 commit 116673f
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
}
`;
29 changes: 18 additions & 11 deletions packages/vest/src/core/VestBus/VestBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 */
Expand All @@ -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);
}
});
Expand Down Expand Up @@ -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();
});

Expand Down
1 change: 1 addition & 0 deletions packages/vestjs-runtime/src/Isolate/Isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function useRunAsNew<Callback extends CB = CB>(
}

emit(RuntimeEvents.ISOLATE_DONE, current);
emit(RuntimeEvents.ASYNC_ISOLATE_DONE, current);
});
} else {
emit(RuntimeEvents.ISOLATE_DONE, current);
Expand Down
3 changes: 2 additions & 1 deletion packages/vestjs-runtime/src/RuntimeEvents.ts
Original file line number Diff line number Diff line change
@@ -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',
};

0 comments on commit 116673f

Please sign in to comment.