@@ -183,7 +183,25 @@ describe('MetricsInstrumentation', () => {
183
183
trackers . forEach ( tracker => expect ( tracker ) . not . toBeCalled ( ) ) ;
184
184
} ) ;
185
185
186
- it ( 'initializes trackers when not on node and `global.performance` is available.' , ( ) => {
186
+ it ( 'does not initialize trackers when not on node but `global.document` is not available (in worker)' , ( ) => {
187
+ // window not necessary for this test, but it is here to exercise that it is absence of document that is checked
188
+ addDOMPropertiesToGlobal ( [ 'performance' , 'addEventListener' , 'window' ] ) ;
189
+ const processBackup = global . process ;
190
+ global . process = undefined ;
191
+ const documentBackup = global . document ;
192
+ global . document = undefined ;
193
+
194
+ const trackers = [ '_trackCLS' , '_trackLCP' , '_trackFID' ] . map ( tracker =>
195
+ jest . spyOn ( MetricsInstrumentation . prototype as any , tracker ) ,
196
+ ) ;
197
+ new MetricsInstrumentation ( ) ;
198
+ global . process = processBackup ;
199
+ global . document = documentBackup ;
200
+
201
+ trackers . forEach ( tracker => expect ( tracker ) . not . toBeCalled ( ) ) ;
202
+ } ) ;
203
+
204
+ it ( 'initializes trackers when not on node and `global.performance` and `global.document` are available.' , ( ) => {
187
205
addDOMPropertiesToGlobal ( [ 'performance' , 'document' , 'addEventListener' , 'window' ] ) ;
188
206
const backup = global . process ;
189
207
global . process = undefined ;
0 commit comments