|
1 | 1 | import { Span, Transaction } from '../../src';
|
2 |
| -import { _startChild, addResourceSpans, ResourceEntry } from '../../src/browser/metrics'; |
| 2 | +import { _startChild, addResourceSpans, MetricsInstrumentation, ResourceEntry } from '../../src/browser/metrics'; |
| 3 | +import { addDOMPropertiesToGlobal } from '../testutils'; |
| 4 | + |
| 5 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-var |
| 6 | +declare var global: any; |
3 | 7 |
|
4 | 8 | describe('_startChild()', () => {
|
5 | 9 | it('creates a span with given properties', () => {
|
@@ -167,3 +171,29 @@ describe('addResourceSpans', () => {
|
167 | 171 | );
|
168 | 172 | });
|
169 | 173 | });
|
| 174 | + |
| 175 | +describe('MetricsInstrumentation', () => { |
| 176 | + it('does not initialize trackers when on node', () => { |
| 177 | + const trackers = ['_trackCLS', '_trackLCP', '_trackFID'].map(tracker => |
| 178 | + jest.spyOn(MetricsInstrumentation.prototype as any, tracker), |
| 179 | + ); |
| 180 | + |
| 181 | + new MetricsInstrumentation(); |
| 182 | + |
| 183 | + trackers.forEach(tracker => expect(tracker).not.toBeCalled()); |
| 184 | + }); |
| 185 | + |
| 186 | + it('initializes trackers when not on node and `global.performance` is available.', () => { |
| 187 | + addDOMPropertiesToGlobal(['performance', 'document', 'addEventListener', 'window']); |
| 188 | + const backup = global.process; |
| 189 | + global.process = undefined; |
| 190 | + |
| 191 | + const trackers = ['_trackCLS', '_trackLCP', '_trackFID'].map(tracker => |
| 192 | + jest.spyOn(MetricsInstrumentation.prototype as any, tracker), |
| 193 | + ); |
| 194 | + new MetricsInstrumentation(); |
| 195 | + global.process = backup; |
| 196 | + |
| 197 | + trackers.forEach(tracker => expect(tracker).toBeCalled()); |
| 198 | + }); |
| 199 | +}); |
0 commit comments