@@ -23,16 +23,45 @@ export class InstanceModifier extends RpcTarget {
2323 this . #state = state ;
2424 }
2525
26+ async #getWaitForEventCacheKey( step : StepSelector ) : Promise < string > {
27+ let count = 1 ;
28+ if ( step . index ) {
29+ count = step . index ;
30+ }
31+ const name = `${ step . name } -${ count } ` ;
32+ const hash = await computeHash ( name ) ;
33+ const cacheKey = `${ hash } -${ count } ` ;
34+ const waitForEventKey = `${ cacheKey } -value` ;
35+
36+ return waitForEventKey ;
37+ }
38+
39+ async #getStepCacheKey( step : StepSelector ) : Promise < string > {
40+ const hash = await computeHash ( step . name ) ;
41+ let count = 1 ;
42+ if ( step . index ) {
43+ count = step . index ;
44+ }
45+ const cacheKey = `${ hash } -${ count } ` ;
46+ const valueKey = `${ cacheKey } -value` ;
47+
48+ return valueKey ;
49+ }
50+
2651 async disableSleeps ( ) : Promise < void > {
2752 await this . #state. storage . put ( "disableSleeps" , true ) ;
2853 }
2954
55+ async mockStepResult ( step : StepSelector , stepResult : unknown ) : Promise < void > {
56+ const valueKey = await this . #getStepCacheKey( step ) ;
57+ await this . #state. storage . put ( `replace-result-${ valueKey } ` , stepResult ) ;
58+ }
59+
3060 async mockEvent ( event : UserEvent ) : Promise < void > {
31- console . log ( "SENDING THE EVENT WITH TYPE" , event . type ) ;
3261 // could maybe:
3362 // WorkflowInstance.sendEvent()
3463 // Engine.receiveEvent()
35- //const waitForEventKey = await this.#getWaitForEventCacheKey(step);
64+ // flag with waitForEventKey
3665
3766 const myEvent : Event = {
3867 timestamp : new Date ( ) ,
@@ -43,19 +72,6 @@ export class InstanceModifier extends RpcTarget {
4372 await this . #engine. receiveEvent ( myEvent ) ;
4473 }
4574
46- async #getWaitForEventCacheKey( step : StepSelector ) : Promise < string > {
47- let count = 1 ;
48- if ( step . index ) {
49- count = step . index ;
50- }
51- const name = `${ step . name } -${ count } ` ;
52- const hash = await computeHash ( name ) ;
53- const cacheKey = `${ hash } -${ count } ` ;
54- const waitForEventKey = `${ cacheKey } -value` ;
55-
56- return waitForEventKey ;
57- }
58-
5975 async forceEventTimeout ( step : StepSelector ) : Promise < void > {
6076 const waitForEventKey = await this . #getWaitForEventCacheKey( step ) ;
6177 await this . #state. storage . put ( `forceEventTimeout-${ waitForEventKey } ` , true ) ;
0 commit comments