@@ -5,9 +5,24 @@ import type { IScenarioCommand, TestScenario } from '../TestScenario.js';
5
5
import { promiseAndResolver } from '../utils/promise.js' ;
6
6
7
7
export 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
+ }
9
15
10
16
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
+
11
26
this . expectEngine . expectTexts . push ( text ) ;
12
27
const { promise, resolve } = promiseAndResolver ( ) ;
13
28
this . expectEngine . once ( 'match' , ( ) => {
@@ -16,6 +31,7 @@ export class WaitSerialCommand implements IScenarioCommand {
16
31
if ( textIndex >= 0 ) {
17
32
this . expectEngine . expectTexts . splice ( textIndex , 1 ) ;
18
33
}
34
+ this . buffer . length = 0 ;
19
35
resolve ( ) ;
20
36
} ) ;
21
37
await Promise . all ( [ scenario . resume ( ) , promise ] ) ;
0 commit comments