@@ -2,9 +2,9 @@ import 'jsdom-worker';
2
2
3
3
import pako from 'pako' ;
4
4
5
+ import { EventBufferProxy } from '../../src/eventBuffer/EventBufferProxy' ;
5
6
import { createEventBuffer } from './../../src/eventBuffer' ;
6
7
import { BASE_TIMESTAMP } from './../index' ;
7
- import { EventBufferProxy } from '../../src/eventBuffer/EventBufferProxy' ;
8
8
9
9
const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 3 } ;
10
10
describe ( 'Unit | eventBuffer' , ( ) => {
@@ -145,6 +145,31 @@ describe('Unit | eventBuffer', () => {
145
145
expect ( restored1 ) . toEqual ( JSON . stringify ( [ TEST_EVENT ] ) ) ;
146
146
expect ( restored2 ) . toEqual ( JSON . stringify ( [ { ...TEST_EVENT , type : 5 } ] ) ) ;
147
147
} ) ;
148
+
149
+ it ( 'handles an error when compressing the payload xxx' , async function ( ) {
150
+ const buffer = createEventBuffer ( {
151
+ useCompression : true ,
152
+ } ) as EventBufferProxy ;
153
+
154
+ expect ( buffer ) . toBeInstanceOf ( EventBufferProxy ) ;
155
+
156
+ // Ensure worker is ready
157
+ await buffer . ensureWorkerIsLoaded ( ) ;
158
+
159
+ buffer . addEvent ( TEST_EVENT ) ;
160
+ buffer . addEvent ( TEST_EVENT ) ;
161
+
162
+ // @ts -ignore Mock this private so it triggers an error
163
+ const postMessageSpy = jest . spyOn ( buffer . _compression , '_postMessage' ) . mockImplementation ( ( ) => {
164
+ return Promise . reject ( 'test worker error' ) ;
165
+ } ) ;
166
+
167
+ const result = await buffer . finish ( ) ;
168
+
169
+ expect ( postMessageSpy ) . toHaveBeenCalledTimes ( 1 ) ;
170
+
171
+ expect ( result ) . toEqual ( JSON . stringify ( [ TEST_EVENT , TEST_EVENT ] ) ) ;
172
+ } ) ;
148
173
} ) ;
149
174
150
175
describe ( 'EventBufferProxy fallback' , ( ) => {
0 commit comments