You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, love the product, now migrating from v4 to v5.
I know you very much recommend event sourcing when you want to replicate being at the state of invoking an actor, alternatively using getPersistedSnapshot at that time and later restoring using snapshot, but I have a use case which is very powerful in v4, and, as far as I can tell, it isn't possible in v5.
and this would execute the invoked service/actor as well as any entry actions (provided execute: true), meaning I could test:
a transition based on a timer, in isolation
entry actions, in isolation
a transition, caused by an invocation result, in isolation_
Here's what the last one can look like:
constservice=interpret(machine.withConfig({services: {// mock the servicemyService: async()=>({,result: "someReturnValue",// Now I can easily test the transition with this service result}),},actions: {// mock the actions, go nuts!someEntryAction: ()=>{},// Only run if { execute: true }someOnDoneAction: ()=>{},someOnErrorAction: ()=>{},someExitAction: ()=>{},},}),{execute: true},);
On the other hand, if I want to do event sourcing, and my machine has many branches and long paths, I'm stuck either maintaining a plethora of event combinations to reconstruct all the transitions I'm interested in testing in isolation, and it woudn't really be in isolation because I would then be dependent upon the correct functionality of all the transitions happening before the one I actually want to test.
Alternative is an integration test per path, which quickly becomes unwieldy. Or, start using model based testing (which I want to do at some point, just not now in the middle of the migration).
I could start the machine at a previous state where a user-land event is accepted and use something like actor.send("START") to kick off a chain of reactions which will eventually invoke the service, but I sometimes have 4 or 5 services in sequence which depend on each other with guards determining the next invoked actor, meaning I have to then mock all of these to test the transition which only comes later.
I guess my question is, is there any way to start a "restored" but un-started invoked actor/action/timer in v5, e.g.:
constinitialState=machine.resolveState({value: "stateWhereInvocationHappens",});constmachine=authorizationIframeMachine.provide({// Provide stubs});constactor=createActor(machine,{snapshot: initialState,});actor.start();// This doesn't start the invoked actor :'(// One way of doing itactor.replayInvokedActors();actor.replayTimers();actor.replayEntryActions();// Manually recreating the event which triggered the transition to the state of the invocation/action/timer would also // satisfy my need. As you can see I'm pretty desperate.actor.$$_testOnlyInternalSend("xstate.done.actor.0.myMachine.actorWhichWhenDoneTriggersTransitionWhichIsSut");actor.$$_testOnlyInternalSend("xstate.after.DELAY.myMachine.aTimerWhichWhenDoneTriggersTransitionWhichIsSut");// Or, more in line with the old APIconstactor=createActor(machine,{snapshot: initialState,execute: {timers: true,actions: true,actors: true,}});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, love the product, now migrating from v4 to v5.
I know you very much recommend event sourcing when you want to replicate being at the state of invoking an actor, alternatively using
getPersistedSnapshot
at that time and later restoring usingsnapshot
, but I have a use case which is very powerful in v4, and, as far as I can tell, it isn't possible in v5.In v4, I could do
and this would execute the invoked service/actor as well as any entry actions (provided
execute: true
), meaning I could test:Here's what the last one can look like:
On the other hand, if I want to do event sourcing, and my machine has many branches and long paths, I'm stuck either maintaining a plethora of event combinations to reconstruct all the transitions I'm interested in testing in isolation, and it woudn't really be in isolation because I would then be dependent upon the correct functionality of all the transitions happening before the one I actually want to test.
Alternative is an integration test per path, which quickly becomes unwieldy. Or, start using model based testing (which I want to do at some point, just not now in the middle of the migration).
I could start the machine at a previous state where a user-land event is accepted and use something like
actor.send("START")
to kick off a chain of reactions which will eventually invoke the service, but I sometimes have 4 or 5 services in sequence which depend on each other with guards determining the next invoked actor, meaning I have to then mock all of these to test the transition which only comes later.I guess my question is, is there any way to start a "restored" but un-started invoked actor/action/timer in v5, e.g.:
Actor repro: https://stackblitz.com/edit/github-wrjkuf-shs9hn?file=restoring.actor.test.ts
Timer repro: https://stackblitz.com/edit/github-wrjkuf-onryx6?file=restoring.timer.test.ts
Action repro: https://stackblitz.com/edit/github-wrjkuf-bufj8z?file=restoring.action.test.ts
Any advice?
Beta Was this translation helpful? Give feedback.
All reactions