Skip to content

Commit 6f5a32a

Browse files
committed
fix type errors in tracing tests
1 parent c605f74 commit 6f5a32a

File tree

7 files changed

+41
-43
lines changed

7 files changed

+41
-43
lines changed

packages/tracing/test/browser/browsertracing.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BrowserClient } from '@sentry/browser';
22
import { Hub, makeMain } from '@sentry/hub';
3-
import { getGlobalObject } from '@sentry/utils';
3+
import { getGlobalObject, InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
44
import { JSDOM } from 'jsdom';
55

66
import {
@@ -23,7 +23,7 @@ jest.mock('@sentry/utils', () => {
2323
const actual = jest.requireActual('@sentry/utils');
2424
return {
2525
...actual,
26-
addInstrumentationHandler: (type, callback): void => {
26+
addInstrumentationHandler: (type: InstrumentHandlerType, callback: InstrumentHandlerCallback): void => {
2727
if (type === 'history') {
2828
// rather than actually add the navigation-change handler, grab a reference to it, so we can trigger it manually
2929
mockChangeHistory = callback;

packages/tracing/test/browser/metrics.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { Span, Transaction } from '../../src';
2-
import {
3-
_startChild,
4-
addResourceSpans,
5-
DEFAULT_METRICS_INSTR_OPTIONS,
6-
MetricsInstrumentation,
7-
ResourceEntry,
8-
} from '../../src/browser/metrics';
2+
import { _startChild, addResourceSpans, MetricsInstrumentation, ResourceEntry } from '../../src/browser/metrics';
93
import { addDOMPropertiesToGlobal } from '../testutils';
104

115
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-var
@@ -186,7 +180,7 @@ describe('MetricsInstrumentation', () => {
186180
jest.spyOn(MetricsInstrumentation.prototype as any, tracker),
187181
);
188182

189-
new MetricsInstrumentation(DEFAULT_METRICS_INSTR_OPTIONS);
183+
new MetricsInstrumentation();
190184

191185
trackers.forEach(tracker => expect(tracker).not.toBeCalled());
192186
});
@@ -200,7 +194,7 @@ describe('MetricsInstrumentation', () => {
200194
const trackers = ['_trackCLS', '_trackLCP', '_trackFID'].map(tracker =>
201195
jest.spyOn(MetricsInstrumentation.prototype as any, tracker),
202196
);
203-
new MetricsInstrumentation(DEFAULT_METRICS_INSTR_OPTIONS);
197+
new MetricsInstrumentation();
204198
global.process = backup;
205199

206200
trackers.forEach(tracker => expect(tracker).toBeCalled());

packages/tracing/test/browser/request.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hub, makeMain } from '@sentry/hub';
33
import * as utils from '@sentry/utils';
44

55
import { Span, spanStatusfromHttpCode, Transaction } from '../../src';
6-
import { fetchCallback, FetchData, instrumentOutgoingRequests, xhrCallback, XHRData } from '../../src/browser/request';
6+
import { fetchCallback, FetchData, instrumentOutgoingRequests, xhrCallback } from '../../src/browser/request';
77
import { addExtensionMethods } from '../../src/hubextensions';
88
import * as tracingUtils from '../../src/utils';
99

@@ -55,7 +55,7 @@ describe('callbacks', () => {
5555
fetchData: { url: 'http://dogs.are.great/', method: 'GET' },
5656
startTimestamp,
5757
};
58-
const xhrHandlerData: XHRData = {
58+
const xhrHandlerData = {
5959
xhr: {
6060
__sentry_xhr__: {
6161
method: 'GET',
@@ -128,17 +128,17 @@ describe('callbacks', () => {
128128
// triggered by request being sent
129129
fetchCallback(fetchHandlerData, alwaysCreateSpan, spans);
130130

131-
const newSpan = transaction.spanRecorder?.spans[1];
131+
const newSpan = transaction.spanRecorder?.spans[1] as Span;
132132

133133
expect(newSpan).toBeDefined();
134134
expect(newSpan).toBeInstanceOf(Span);
135-
expect(newSpan!.data).toEqual({
135+
expect(newSpan.data).toEqual({
136136
method: 'GET',
137137
type: 'fetch',
138138
url: 'http://dogs.are.great/',
139139
});
140-
expect(newSpan!.description).toBe('GET http://dogs.are.great/');
141-
expect(newSpan!.op).toBe('http.client');
140+
expect(newSpan.description).toBe('GET http://dogs.are.great/');
141+
expect(newSpan.op).toBe('http.client');
142142
expect(fetchHandlerData.fetchData?.__span).toBeDefined();
143143

144144
const postRequestFetchHandlerData = {
@@ -149,7 +149,7 @@ describe('callbacks', () => {
149149
// triggered by response coming back
150150
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, spans);
151151

152-
expect(newSpan!.endTimestamp).toBeDefined();
152+
expect(newSpan.endTimestamp).toBeDefined();
153153
});
154154

155155
it('sets response status on finish', () => {
@@ -158,7 +158,7 @@ describe('callbacks', () => {
158158
// triggered by request being sent
159159
fetchCallback(fetchHandlerData, alwaysCreateSpan, spans);
160160

161-
const newSpan = transaction.spanRecorder?.spans[1];
161+
const newSpan = transaction.spanRecorder?.spans[1] as Span;
162162

163163
expect(newSpan).toBeDefined();
164164

@@ -171,7 +171,7 @@ describe('callbacks', () => {
171171
// triggered by response coming back
172172
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, spans);
173173

174-
expect(newSpan!.status).toBe(spanStatusfromHttpCode(404));
174+
expect(newSpan.status).toBe(spanStatusfromHttpCode(404));
175175
});
176176

177177
it('ignores response with no associated span', () => {
@@ -236,18 +236,18 @@ describe('callbacks', () => {
236236
// triggered by request being sent
237237
xhrCallback(xhrHandlerData, alwaysCreateSpan, spans);
238238

239-
const newSpan = transaction.spanRecorder?.spans[1];
239+
const newSpan = transaction.spanRecorder?.spans[1] as Span;
240240

241241
expect(newSpan).toBeInstanceOf(Span);
242-
expect(newSpan!.data).toEqual({
242+
expect(newSpan.data).toEqual({
243243
method: 'GET',
244244
type: 'xhr',
245245
url: 'http://dogs.are.great/',
246246
});
247-
expect(newSpan!.description).toBe('GET http://dogs.are.great/');
248-
expect(newSpan!.op).toBe('http.client');
249-
expect(xhrHandlerData.xhr!.__sentry_xhr_span_id__).toBeDefined();
250-
expect(xhrHandlerData.xhr!.__sentry_xhr_span_id__).toEqual(newSpan?.spanId);
247+
expect(newSpan.description).toBe('GET http://dogs.are.great/');
248+
expect(newSpan.op).toBe('http.client');
249+
expect(xhrHandlerData.xhr.__sentry_xhr_span_id__).toBeDefined();
250+
expect(xhrHandlerData.xhr.__sentry_xhr_span_id__).toEqual(newSpan?.spanId);
251251

252252
const postRequestXHRHandlerData = {
253253
...xhrHandlerData,
@@ -257,7 +257,7 @@ describe('callbacks', () => {
257257
// triggered by response coming back
258258
xhrCallback(postRequestXHRHandlerData, alwaysCreateSpan, spans);
259259

260-
expect(newSpan!.endTimestamp).toBeDefined();
260+
expect(newSpan.endTimestamp).toBeDefined();
261261
});
262262

263263
it('sets response status on finish', () => {
@@ -266,20 +266,20 @@ describe('callbacks', () => {
266266
// triggered by request being sent
267267
xhrCallback(xhrHandlerData, alwaysCreateSpan, spans);
268268

269-
const newSpan = transaction.spanRecorder?.spans[1];
269+
const newSpan = transaction.spanRecorder?.spans[1] as Span;
270270

271271
expect(newSpan).toBeDefined();
272272

273273
const postRequestXHRHandlerData = {
274274
...xhrHandlerData,
275275
endTimestamp,
276276
};
277-
postRequestXHRHandlerData.xhr!.__sentry_xhr__!.status_code = 404;
277+
postRequestXHRHandlerData.xhr.__sentry_xhr__.status_code = 404;
278278

279279
// triggered by response coming back
280280
xhrCallback(postRequestXHRHandlerData, alwaysCreateSpan, spans);
281281

282-
expect(newSpan!.status).toBe(spanStatusfromHttpCode(404));
282+
expect(newSpan.status).toBe(spanStatusfromHttpCode(404));
283283
});
284284

285285
it('ignores response with no associated span', () => {

packages/tracing/test/browser/router.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
12
import { JSDOM } from 'jsdom';
23

34
import { instrumentRoutingWithDefaults } from '../../src/browser/router';
@@ -8,7 +9,7 @@ jest.mock('@sentry/utils', () => {
89
const actual = jest.requireActual('@sentry/utils');
910
return {
1011
...actual,
11-
addInstrumentationHandler: (type, callback): void => {
12+
addInstrumentationHandler: (type: InstrumentHandlerType, callback: InstrumentHandlerCallback): void => {
1213
addInstrumentationHandlerType = type;
1314
mockChangeHistory = callback;
1415
},

packages/tracing/test/errors.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { BrowserClient } from '@sentry/browser';
22
import { Hub, makeMain } from '@sentry/hub';
3+
import { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
34

45
import { registerErrorInstrumentation } from '../src/errors';
56
import { _addTracingExtensions } from '../src/hubextensions';
67

78
const mockAddInstrumentationHandler = jest.fn();
8-
let mockErrorCallback: () => void = () => undefined;
9-
let mockUnhandledRejectionCallback: () => void = () => undefined;
9+
let mockErrorCallback: InstrumentHandlerCallback = () => undefined;
10+
let mockUnhandledRejectionCallback: InstrumentHandlerCallback = () => undefined;
1011
jest.mock('@sentry/utils', () => {
1112
const actual = jest.requireActual('@sentry/utils');
1213
return {
1314
...actual,
14-
addInstrumentationHandler: (type, callback) => {
15+
addInstrumentationHandler: (type: InstrumentHandlerType, callback: InstrumentHandlerCallback) => {
1516
if (type === 'error') {
1617
mockErrorCallback = callback;
1718
}
@@ -53,10 +54,10 @@ describe('registerErrorHandlers()', () => {
5354
const transaction = hub.startTransaction({ name: 'test' });
5455
expect(transaction.status).toBe(undefined);
5556

56-
mockErrorCallback();
57+
mockErrorCallback({});
5758
expect(transaction.status).toBe(undefined);
5859

59-
mockUnhandledRejectionCallback();
60+
mockUnhandledRejectionCallback({});
6061
expect(transaction.status).toBe(undefined);
6162
transaction.finish();
6263
});
@@ -66,7 +67,7 @@ describe('registerErrorHandlers()', () => {
6667
const transaction = hub.startTransaction({ name: 'test' });
6768
hub.configureScope(scope => scope.setSpan(transaction));
6869

69-
mockErrorCallback();
70+
mockErrorCallback({});
7071
expect(transaction.status).toBe('internal_error');
7172

7273
transaction.finish();
@@ -77,7 +78,7 @@ describe('registerErrorHandlers()', () => {
7778
const transaction = hub.startTransaction({ name: 'test' });
7879
hub.configureScope(scope => scope.setSpan(transaction));
7980

80-
mockUnhandledRejectionCallback();
81+
mockUnhandledRejectionCallback({});
8182
expect(transaction.status).toBe('internal_error');
8283
transaction.finish();
8384
});

packages/tracing/test/idletransaction.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
} from '../src/idletransaction';
1010
import { Span } from '../src/span';
1111

12-
export class SimpleTransport extends Transports.BaseTransport {}
12+
// @ts-ignore It's okay that we're not implementing the methods of the abstract `BaseTransport` class, because it's not
13+
// what we're testing here
14+
class SimpleTransport extends Transports.BaseTransport {}
1315

1416
const dsn = 'https://[email protected]/42';
1517
let hub: Hub;
@@ -166,9 +168,9 @@ describe('IdleTransaction', () => {
166168
it('should record dropped transactions', async () => {
167169
const transaction = new IdleTransaction({ name: 'foo', startTimestamp: 1234, sampled: false }, hub, 1000);
168170

169-
const transport = hub.getClient()?.getTransport();
171+
const transport = hub.getClient()!.getTransport!();
170172

171-
const spy = jest.spyOn(transport!, 'recordLostEvent');
173+
const spy = jest.spyOn(transport, 'recordLostEvent');
172174

173175
transaction.initSpanRecorder(10);
174176
transaction.finish(transaction.startTimestamp + 10);

packages/utils/src/instrument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { supportsHistory, supportsNativeFetch } from './supports';
1313

1414
const global = getGlobalObject<Window>();
1515

16-
type InstrumentHandlerType =
16+
export type InstrumentHandlerType =
1717
| 'console'
1818
| 'dom'
1919
| 'fetch'
@@ -22,7 +22,7 @@ type InstrumentHandlerType =
2222
| 'xhr'
2323
| 'error'
2424
| 'unhandledrejection';
25-
type InstrumentHandlerCallback = (data: any) => void;
25+
export type InstrumentHandlerCallback = (data: any) => void;
2626

2727
/**
2828
* Instrument native APIs to call handlers that can be used to create breadcrumbs, APM spans etc.

0 commit comments

Comments
 (0)