@@ -5,9 +5,24 @@ import type { IScenarioCommand, TestScenario } from '../TestScenario.js';
55import { promiseAndResolver } from '../utils/promise.js' ;
66
77export class WaitSerialCommand implements IScenarioCommand {
8- constructor ( readonly expectEngine : ExpectEngine ) { }
8+ readonly buffer : string [ ] = [ ] ;
9+
10+ constructor ( readonly expectEngine : ExpectEngine ) {
11+ expectEngine . on ( 'line' , ( line ) => {
12+ this . buffer . push ( line ) ;
13+ } ) ;
14+ }
915
1016 async run ( scenario : TestScenario , client : APIClient , text : string ) {
17+ for ( let i = 0 ; i < this . buffer . length ; i ++ ) {
18+ const line = this . buffer [ i ] ;
19+ if ( line . includes ( text ) ) {
20+ this . buffer . splice ( 0 , i + 1 ) ;
21+ scenario . log ( chalkTemplate `Expected text matched: {green "${ text } "}` ) ;
22+ return ;
23+ }
24+ }
25+
1126 this . expectEngine . expectTexts . push ( text ) ;
1227 const { promise, resolve } = promiseAndResolver ( ) ;
1328 this . expectEngine . once ( 'match' , ( ) => {
@@ -16,6 +31,7 @@ export class WaitSerialCommand implements IScenarioCommand {
1631 if ( textIndex >= 0 ) {
1732 this . expectEngine . expectTexts . splice ( textIndex , 1 ) ;
1833 }
34+ this . buffer . length = 0 ;
1935 resolve ( ) ;
2036 } ) ;
2137 await Promise . all ( [ scenario . resume ( ) , promise ] ) ;
0 commit comments