88
99const DEFAULT_STEP_TIMEOUT = 10_000 ;
1010
11- type Step = { id : number ; timeout ?: number } & (
11+ type Step = { id : number ; timeout ?: number ; stepWrapperName : string } & (
1212 | {
1313 type : "prompt" ;
1414 promptIndex : number ;
@@ -36,6 +36,8 @@ export class ScenarioBuilder implements InteractionBuilder {
3636 #stepCount = 0 ;
3737 #promptResponses: Record < number , string | string [ ] > ;
3838
39+ #stepWrapperStack: Array < string > = [ ] ;
40+
3941 constructor ( testEnv : TestEnv ) {
4042 this . #testEnv = testEnv ;
4143 this . #steps = [ ] ;
@@ -63,6 +65,7 @@ export class ScenarioBuilder implements InteractionBuilder {
6365 promptIndex : this . #promptCount,
6466 timeout : opts ?. timeout ,
6567 output : stdout ,
68+ stepWrapperName : this . #stepWrapperStack. join ( " > " ) ,
6669 } ) ;
6770
6871 return {
@@ -73,6 +76,7 @@ export class ScenarioBuilder implements InteractionBuilder {
7376 } ,
7477 } ;
7578 }
79+
7680 /**
7781 * Expect the specific `stdout` CLI output.
7882 *
@@ -88,6 +92,7 @@ export class ScenarioBuilder implements InteractionBuilder {
8892 type : "output" ,
8993 output,
9094 timeout : opts ?. timeout ,
95+ stepWrapperName : this . #stepWrapperStack. join ( " > " ) ,
9196 } ) ;
9297 return this ;
9398 }
@@ -104,14 +109,19 @@ export class ScenarioBuilder implements InteractionBuilder {
104109 name : string ,
105110 stepCallback : ( actions : Actions ) => void
106111 ) : InteractionBuilder {
112+ this . #stepWrapperStack. push ( name ) ;
113+
107114 try {
108115 stepCallback ( {
109116 whenAsked : this . whenAsked . bind ( this ) ,
110117 expectOutput : this . expectOutput . bind ( this ) ,
111118 } ) ;
112119 } catch ( e ) {
113120 throw new Error ( `Error in step '${ name } ', ${ e } ` ) ;
121+ } finally {
122+ this . #stepWrapperStack. pop ( ) ;
114123 }
124+
115125 return this ;
116126 }
117127
@@ -181,9 +191,13 @@ export class ScenarioBuilder implements InteractionBuilder {
181191 try {
182192 await this . #waitForOutput( step ) ;
183193 } catch {
194+ const errPrefix = step . stepWrapperName
195+ ? step . stepWrapperName + " > "
196+ : "" ;
197+
184198 reject (
185199 new Error (
186- `Timeout waiting on ${
200+ `${ errPrefix } Timeout waiting on ${
187201 step . type === "prompt" ? "prompt" : "output"
188202 } .
189203Waiting for:
0 commit comments