Skip to content

Commit

Permalink
patch(vest): emit an event when all tests are done running
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Feb 16, 2022
1 parent c1ebb9b commit ebd8188
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/vest/src/core/suite/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function create<T extends CB>(

// Report the suite is done registering tests
// Async tests may still be running
bus.emit(Events.SUITE_COMPLETED);
bus.emit(Events.SUITE_CALLBACK_DONE_RUNNING);

// Return the result
return produceFullResult();
Expand Down
4 changes: 1 addition & 3 deletions packages/vest/src/core/suite/produce/runCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@ export function runFieldCallbacks(fieldName?: string): void {
*/
export function runDoneCallbacks() {
const [{ doneCallbacks }] = useTestCallbacks();
if (!hasRemainingTests()) {
callEach(doneCallbacks);
}
callEach(doneCallbacks);
}
17 changes: 14 additions & 3 deletions packages/vest/src/core/vestBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import throwError from 'throwError';

import VestTest from 'VestTest';
import ctx from 'ctx';
import hasRemainingTests from 'hasRemainingTests';
import matchingFieldName from 'matchingFieldName';
import omitOptionalTests from 'omitOptionalTests';
import removeTestFromState from 'removeTestFromState';
Expand All @@ -23,16 +24,25 @@ export function initBus() {
testObject.done();

runFieldCallbacks(testObject.fieldName);
runDoneCallbacks();

if (!hasRemainingTests()) {
// When no more tests are running, emit the done event
bus.emit(Events.ALL_RUNNING_TESTS_FINISHED);
}
});

// Report that the suite completed its synchronous test run.
// Async operations may still be running.
bus.on(Events.SUITE_COMPLETED, () => {
bus.on(Events.SUITE_CALLBACK_DONE_RUNNING, () => {
// Remove tests that are optional and need to be omitted
omitOptionalTests();
});

// Called when all the tests, including async, are done running
bus.on(Events.ALL_RUNNING_TESTS_FINISHED, () => {
runDoneCallbacks();
});

// Removes a certain field from the state.
bus.on(Events.REMOVE_FIELD, (fieldName: string) => {
useEachTestObject(testObject => {
Expand Down Expand Up @@ -67,7 +77,8 @@ export function useBus() {

export enum Events {
TEST_COMPLETED = 'test_completed',
ALL_RUNNING_TESTS_FINISHED = 'all_running_tests_finished',
REMOVE_FIELD = 'remove_field',
RESET_FIELD = 'reset_field',
SUITE_COMPLETED = 'suite_completed',
SUITE_CALLBACK_DONE_RUNNING = 'suite_callback_done_running',
}

1 comment on commit ebd8188

@vercel
Copy link

@vercel vercel bot commented on ebd8188 Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next-ealush.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-website.vercel.app

Please sign in to comment.