Skip to content

Commit

Permalink
patch(vest): remove duplicate state transition functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 12, 2024
1 parent 22f12e9 commit cf6426c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
15 changes: 2 additions & 13 deletions packages/vest/src/core/StateMachines/CommonStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { TIsolate } from 'vestjs-runtime';
export const CommonStates = {
PENDING: 'PENDING',
INITIAL: 'INITIAL',
DONE: 'DONE',
};

const State = {
[CommonStates.PENDING]: CommonStates.PENDING,
[CommonStates.INITIAL]: CommonStates.INITIAL,
DONE: 'DONE',
[CommonStates.DONE]: CommonStates.DONE,
};

export type State = ValueOf<typeof State>;
Expand All @@ -28,16 +29,4 @@ const machine: TStateMachine<State> = {
},
};

function transition(from: State | undefined, to: State) {
return CommonStateMachine.staticTransition(from ?? State.INITIAL, to);
}

export function setDone(isolate: TIsolate) {
isolate.status = transition(isolate.status, State.DONE);
}

export function setPending(isolate: TIsolate) {
isolate.status = transition(isolate.status, State.PENDING);
}

export const CommonStateMachine = StateMachine<State>(machine);
6 changes: 3 additions & 3 deletions packages/vest/src/core/VestBus/VestBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CB, ValueOf } from 'vest-utils';
import { Bus, RuntimeEvents, TIsolate } from 'vestjs-runtime';

import { Events } from 'BusEvents';
import * as CommonStateMachine from 'CommonStateMachine';
import { TIsolateTest } from 'IsolateTest';
import {
useExpireSuiteResultCache,
Expand All @@ -12,6 +11,7 @@ import {
import { TFieldName } from 'SuiteResultTypes';
import { SuiteWalker } from 'SuiteWalker';
import { TestWalker } from 'TestWalker';
import { VestIsolate } from 'VestIsolate';
import { VestTest } from 'VestTest';
import { useOmitOptionalFields } from 'omitOptionalFields';
import { useRunDoneCallbacks, useRunFieldCallbacks } from 'runCallbacks';
Expand Down Expand Up @@ -41,15 +41,15 @@ export function useInitVestBus() {
VestTest.setPending(isolate);
}

CommonStateMachine.setPending(isolate);
VestIsolate.setPending(isolate);
});

on(RuntimeEvents.ISOLATE_DONE, (isolate: TIsolate) => {
if (VestTest.is(isolate)) {
VestBus.emit(Events.TEST_COMPLETED, isolate);
}

CommonStateMachine.setDone(isolate);
VestIsolate.setDone(isolate);

if (!SuiteWalker.hasPending()) {
// When no more tests are running, emit the done event
Expand Down
4 changes: 4 additions & 0 deletions packages/vest/src/core/isolate/VestIsolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class VestIsolate {
this.setStatus(isolate, CommonStates.PENDING);
}

static setDone(isolate: TIsolate): void {
this.setStatus(isolate, CommonStates.DONE);
}

static isPending(isolate: TIsolate): boolean {
return VestIsolate.statusEquals(isolate, CommonStates.PENDING);
}
Expand Down

0 comments on commit cf6426c

Please sign in to comment.