From cf6426c78fe78f23d73ae02e802137a587485e6c Mon Sep 17 00:00:00 2001 From: Evyatar Date: Wed, 12 Jun 2024 13:24:22 +0300 Subject: [PATCH] patch(vest): remove duplicate state transition functions --- .../src/core/StateMachines/CommonStateMachine.ts | 15 ++------------- packages/vest/src/core/VestBus/VestBus.ts | 6 +++--- packages/vest/src/core/isolate/VestIsolate.ts | 4 ++++ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/vest/src/core/StateMachines/CommonStateMachine.ts b/packages/vest/src/core/StateMachines/CommonStateMachine.ts index fdfb1adaa..f6f061e72 100644 --- a/packages/vest/src/core/StateMachines/CommonStateMachine.ts +++ b/packages/vest/src/core/StateMachines/CommonStateMachine.ts @@ -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; @@ -28,16 +29,4 @@ const machine: TStateMachine = { }, }; -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(machine); diff --git a/packages/vest/src/core/VestBus/VestBus.ts b/packages/vest/src/core/VestBus/VestBus.ts index 311a19ea0..704ce8d8d 100644 --- a/packages/vest/src/core/VestBus/VestBus.ts +++ b/packages/vest/src/core/VestBus/VestBus.ts @@ -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, @@ -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'; @@ -41,7 +41,7 @@ export function useInitVestBus() { VestTest.setPending(isolate); } - CommonStateMachine.setPending(isolate); + VestIsolate.setPending(isolate); }); on(RuntimeEvents.ISOLATE_DONE, (isolate: TIsolate) => { @@ -49,7 +49,7 @@ export function useInitVestBus() { 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 diff --git a/packages/vest/src/core/isolate/VestIsolate.ts b/packages/vest/src/core/isolate/VestIsolate.ts index 99678422a..fb82a991b 100644 --- a/packages/vest/src/core/isolate/VestIsolate.ts +++ b/packages/vest/src/core/isolate/VestIsolate.ts @@ -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); }