@@ -5,6 +5,7 @@ import type { Emitter, AndroidEntry, IosEntry } from 'logkitten';
5
5
import { Level , logkitten } from 'logkitten' ;
6
6
import type { DetoxAllure2AdapterDeviceLogsOptions } from '../types' ;
7
7
import type { DeviceWrapper } from '../utils' ;
8
+ import { Deferred } from '../utils' ;
8
9
9
10
import { PIDEntryCollection } from './pid-entry-collection' ;
10
11
@@ -32,6 +33,7 @@ export class LogBuffer implements StepLogRecorder {
32
33
private readonly _appEntries = new PIDEntryCollection ( ) ;
33
34
private readonly _detoxEntries = new PIDEntryCollection ( ) ;
34
35
private _options : DetoxAllure2AdapterDeviceLogsOptions ;
36
+ private readonly _deferreds = new Set < Deferred < number > > ( ) ;
35
37
36
38
constructor ( readonly _config : LogBufferOptions ) {
37
39
const deviceId = this . _config . device . id ;
@@ -102,8 +104,32 @@ export class LogBuffer implements StepLogRecorder {
102
104
}
103
105
} ;
104
106
107
+ private _updateDeferreds ( ts : number ) {
108
+ for ( const deferred of this . _deferreds ) {
109
+ deferred . update ( ts ) ;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Waits until a log entry with timestamp > reference is seen, or times out.
115
+ * @param reference timestamp to compare against
116
+ * @param timeoutMs timeout in ms (default 1000)
117
+ */
118
+ public ensureIntegrity ( reference : number , timeoutMs = 1000 ) : Promise < void > {
119
+ const deferred = new Deferred < number > ( {
120
+ timeoutMs,
121
+ predicate : ( ts ) => ts > reference ,
122
+ cleanup : ( ) => {
123
+ this . _deferreds . delete ( deferred ) ;
124
+ } ,
125
+ } ) ;
126
+ this . _deferreds . add ( deferred ) ;
127
+ return deferred . promise . then ( ( ) => { } ) ; // resolve to void
128
+ }
129
+
105
130
private readonly _onEntry = ( entry : AnyEntry ) => {
106
131
this . _appEntries . push ( entry ) ;
132
+ this . _updateDeferreds ( entry . ts ) ;
107
133
} ;
108
134
109
135
private _iosFilter ( entry : IosEntry ) : boolean {
0 commit comments