@@ -132,6 +132,7 @@ describe('Unit | eventBuffer', () => {
132132 buffer . addEvent ( TEST_EVENT ) ;
133133
134134 const promise1 = buffer . finish ( ) ;
135+ await new Promise ( process . nextTick ) ;
135136
136137 buffer . addEvent ( { ...TEST_EVENT , type : 5 } ) ;
137138 const promise2 = buffer . finish ( ) ;
@@ -146,7 +147,7 @@ describe('Unit | eventBuffer', () => {
146147 expect ( restored2 ) . toEqual ( JSON . stringify ( [ { ...TEST_EVENT , type : 5 } ] ) ) ;
147148 } ) ;
148149
149- it ( 'handles an error when compressing the payload xxx ' , async function ( ) {
150+ it ( 'handles an error when compressing the payload' , async function ( ) {
150151 const buffer = createEventBuffer ( {
151152 useCompression : true ,
152153 } ) as EventBufferProxy ;
@@ -184,7 +185,7 @@ describe('Unit | eventBuffer', () => {
184185 consoleErrorSpy . mockRestore ( ) ;
185186 } ) ;
186187
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 ( ) {
188189 const buffer = createEventBuffer ( {
189190 useCompression : true ,
190191 } ) as EventBufferProxy ;
@@ -196,26 +197,10 @@ describe('Unit | eventBuffer', () => {
196197
197198 expect ( buffer . pendingEvents ) . toEqual ( [ TEST_EVENT , TEST_EVENT ] ) ;
198199
199- // Finish before the worker is loaded
200200 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 ] ) ) ;
219204 } ) ;
220205
221206 it ( 'keeps using simple buffer if worker cannot be loaded' , async function ( ) {
0 commit comments