@@ -132,6 +132,7 @@ describe('Unit | eventBuffer', () => {
132
132
buffer . addEvent ( TEST_EVENT ) ;
133
133
134
134
const promise1 = buffer . finish ( ) ;
135
+ await new Promise ( process . nextTick ) ;
135
136
136
137
buffer . addEvent ( { ...TEST_EVENT , type : 5 } ) ;
137
138
const promise2 = buffer . finish ( ) ;
@@ -146,7 +147,7 @@ describe('Unit | eventBuffer', () => {
146
147
expect ( restored2 ) . toEqual ( JSON . stringify ( [ { ...TEST_EVENT , type : 5 } ] ) ) ;
147
148
} ) ;
148
149
149
- it ( 'handles an error when compressing the payload xxx ' , async function ( ) {
150
+ it ( 'handles an error when compressing the payload' , async function ( ) {
150
151
const buffer = createEventBuffer ( {
151
152
useCompression : true ,
152
153
} ) as EventBufferProxy ;
@@ -184,7 +185,7 @@ describe('Unit | eventBuffer', () => {
184
185
consoleErrorSpy . mockRestore ( ) ;
185
186
} ) ;
186
187
187
- it ( 'first uses simple buffer, and switches over once worker is loaded ' , async function ( ) {
188
+ it ( 'waits for the worker to be loaded when calling finish ' , async function ( ) {
188
189
const buffer = createEventBuffer ( {
189
190
useCompression : true ,
190
191
} ) as EventBufferProxy ;
@@ -196,26 +197,10 @@ describe('Unit | eventBuffer', () => {
196
197
197
198
expect ( buffer . pendingEvents ) . toEqual ( [ TEST_EVENT , TEST_EVENT ] ) ;
198
199
199
- // Finish before the worker is loaded
200
200
const result = await buffer . finish ( ) ;
201
- expect ( typeof result ) . toBe ( 'string' ) ;
202
- expect ( result ) . toEqual ( JSON . stringify ( [ TEST_EVENT , TEST_EVENT ] ) ) ;
203
-
204
- // Now actually finish loading the worker
205
- await buffer . ensureWorkerIsLoaded ( ) ;
206
-
207
- buffer . addEvent ( TEST_EVENT ) ;
208
- buffer . addEvent ( TEST_EVENT ) ;
209
- buffer . addEvent ( TEST_EVENT ) ;
210
-
211
- expect ( buffer . pendingEvents ) . toEqual ( [ TEST_EVENT , TEST_EVENT , TEST_EVENT ] ) ;
212
-
213
- const result2 = await buffer . finish ( ) ;
214
- expect ( result2 ) . toBeInstanceOf ( Uint8Array ) ;
215
-
216
- const restored2 = pako . inflate ( result2 as Uint8Array , { to : 'string' } ) ;
217
-
218
- expect ( restored2 ) . toEqual ( JSON . stringify ( [ TEST_EVENT , TEST_EVENT , TEST_EVENT ] ) ) ;
201
+ expect ( result ) . toBeInstanceOf ( Uint8Array ) ;
202
+ const restored = pako . inflate ( result as Uint8Array , { to : 'string' } ) ;
203
+ expect ( restored ) . toEqual ( JSON . stringify ( [ TEST_EVENT , TEST_EVENT ] ) ) ;
219
204
} ) ;
220
205
221
206
it ( 'keeps using simple buffer if worker cannot be loaded' , async function ( ) {
0 commit comments