Skip to content

Commit

Permalink
test: add test case exercising this
Browse files Browse the repository at this point in the history
  • Loading branch information
gthb committed Aug 31, 2021
1 parent 1647035 commit 0f07e89
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/tracing/test/browser/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,25 @@ describe('MetricsInstrumentation', () => {
trackers.forEach(tracker => expect(tracker).not.toBeCalled());
});

it('initializes trackers when not on node and `global.performance` is available.', () => {
it('does not initialize trackers when not on node but `global.document` is not available (in worker)', () => {
// window not necessary for this test, but it is here to exercise that it is absence of document that is checked
addDOMPropertiesToGlobal(['performance', 'addEventListener', 'window']);
const processBackup = global.process;
global.process = undefined;
const documentBackup = global.document;
global.document = undefined;

const trackers = ['_trackCLS', '_trackLCP', '_trackFID'].map(tracker =>
jest.spyOn(MetricsInstrumentation.prototype as any, tracker),
);
new MetricsInstrumentation();
global.process = processBackup;
global.document = documentBackup;

trackers.forEach(tracker => expect(tracker).not.toBeCalled());
});

it('initializes trackers when not on node and `global.performance` and `global.document` are available.', () => {
addDOMPropertiesToGlobal(['performance', 'document', 'addEventListener', 'window']);
const backup = global.process;
global.process = undefined;
Expand Down

0 comments on commit 0f07e89

Please sign in to comment.