Skip to content

Commit 2e907bc

Browse files
committed
fix type errors in tracing tests
1 parent 00860e2 commit 2e907bc

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,7 +1,7 @@
11
import { BrowserClient } from '@sentry/browser';
22
import { setupBrowserTransport } from '@sentry/browser/src/transports';
33
import { Hub, makeMain } from '@sentry/hub';
4-
import { getGlobalObject } from '@sentry/utils';
4+
import { getGlobalObject, InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
55
import { JSDOM } from 'jsdom';
66

77
import {
@@ -24,7 +24,7 @@ jest.mock('@sentry/utils', () => {
2424
const actual = jest.requireActual('@sentry/utils');
2525
return {
2626
...actual,
27-
addInstrumentationHandler: (type, callback): void => {
27+
addInstrumentationHandler: (type: InstrumentHandlerType, callback: InstrumentHandlerCallback): void => {
2828
if (type === 'history') {
2929
// rather than actually add the navigation-change handler, grab a reference to it, so we can trigger it manually
3030
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
@@ -4,7 +4,7 @@ import { Hub, makeMain } from '@sentry/hub';
44
import * as utils from '@sentry/utils';
55

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

@@ -56,7 +56,7 @@ describe('callbacks', () => {
5656
fetchData: { url: 'http://dogs.are.great/', method: 'GET' },
5757
startTimestamp,
5858
};
59-
const xhrHandlerData: XHRData = {
59+
const xhrHandlerData = {
6060
xhr: {
6161
__sentry_xhr__: {
6262
method: 'GET',
@@ -130,17 +130,17 @@ describe('callbacks', () => {
130130
// triggered by request being sent
131131
fetchCallback(fetchHandlerData, alwaysCreateSpan, spans);
132132

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

135135
expect(newSpan).toBeDefined();
136136
expect(newSpan).toBeInstanceOf(Span);
137-
expect(newSpan!.data).toEqual({
137+
expect(newSpan.data).toEqual({
138138
method: 'GET',
139139
type: 'fetch',
140140
url: 'http://dogs.are.great/',
141141
});
142-
expect(newSpan!.description).toBe('GET http://dogs.are.great/');
143-
expect(newSpan!.op).toBe('http.client');
142+
expect(newSpan.description).toBe('GET http://dogs.are.great/');
143+
expect(newSpan.op).toBe('http.client');
144144
expect(fetchHandlerData.fetchData?.__span).toBeDefined();
145145

146146
const postRequestFetchHandlerData = {
@@ -151,7 +151,7 @@ describe('callbacks', () => {
151151
// triggered by response coming back
152152
fetchCallback(postRequestFetchHandlerData, alwaysCreateSpan, spans);
153153

154-
expect(newSpan!.endTimestamp).toBeDefined();
154+
expect(newSpan.endTimestamp).toBeDefined();
155155
});
156156

157157
it('sets response status on finish', () => {
@@ -160,7 +160,7 @@ describe('callbacks', () => {
160160
// triggered by request being sent
161161
fetchCallback(fetchHandlerData, alwaysCreateSpan, spans);
162162

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

165165
expect(newSpan).toBeDefined();
166166

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

176-
expect(newSpan!.status).toBe(spanStatusfromHttpCode(404));
176+
expect(newSpan.status).toBe(spanStatusfromHttpCode(404));
177177
});
178178

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

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

243243
expect(newSpan).toBeInstanceOf(Span);
244-
expect(newSpan!.data).toEqual({
244+
expect(newSpan.data).toEqual({
245245
method: 'GET',
246246
type: 'xhr',
247247
url: 'http://dogs.are.great/',
248248
});
249-
expect(newSpan!.description).toBe('GET http://dogs.are.great/');
250-
expect(newSpan!.op).toBe('http.client');
251-
expect(xhrHandlerData.xhr!.__sentry_xhr_span_id__).toBeDefined();
252-
expect(xhrHandlerData.xhr!.__sentry_xhr_span_id__).toEqual(newSpan?.spanId);
249+
expect(newSpan.description).toBe('GET http://dogs.are.great/');
250+
expect(newSpan.op).toBe('http.client');
251+
expect(xhrHandlerData.xhr.__sentry_xhr_span_id__).toBeDefined();
252+
expect(xhrHandlerData.xhr.__sentry_xhr_span_id__).toEqual(newSpan?.spanId);
253253

254254
const postRequestXHRHandlerData = {
255255
...xhrHandlerData,
@@ -259,7 +259,7 @@ describe('callbacks', () => {
259259
// triggered by response coming back
260260
xhrCallback(postRequestXHRHandlerData, alwaysCreateSpan, spans);
261261

262-
expect(newSpan!.endTimestamp).toBeDefined();
262+
expect(newSpan.endTimestamp).toBeDefined();
263263
});
264264

265265
it('sets response status on finish', () => {
@@ -268,20 +268,20 @@ describe('callbacks', () => {
268268
// triggered by request being sent
269269
xhrCallback(xhrHandlerData, alwaysCreateSpan, spans);
270270

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

273273
expect(newSpan).toBeDefined();
274274

275275
const postRequestXHRHandlerData = {
276276
...xhrHandlerData,
277277
endTimestamp,
278278
};
279-
postRequestXHRHandlerData.xhr!.__sentry_xhr__!.status_code = 404;
279+
postRequestXHRHandlerData.xhr.__sentry_xhr__.status_code = 404;
280280

281281
// triggered by response coming back
282282
xhrCallback(postRequestXHRHandlerData, alwaysCreateSpan, spans);
283283

284-
expect(newSpan!.status).toBe(spanStatusfromHttpCode(404));
284+
expect(newSpan.status).toBe(spanStatusfromHttpCode(404));
285285
});
286286

287287
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,18 +1,19 @@
11
import { BrowserClient } from '@sentry/browser';
22
import { setupBrowserTransport } from '@sentry/browser/src/transports';
33
import { Hub, makeMain } from '@sentry/hub';
4+
import { InstrumentHandlerCallback, InstrumentHandlerType } from '@sentry/utils';
45

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

89
const mockAddInstrumentationHandler = jest.fn();
9-
let mockErrorCallback: () => void = () => undefined;
10-
let mockUnhandledRejectionCallback: () => void = () => undefined;
10+
let mockErrorCallback: InstrumentHandlerCallback = () => undefined;
11+
let mockUnhandledRejectionCallback: InstrumentHandlerCallback = () => undefined;
1112
jest.mock('@sentry/utils', () => {
1213
const actual = jest.requireActual('@sentry/utils');
1314
return {
1415
...actual,
15-
addInstrumentationHandler: (type, callback) => {
16+
addInstrumentationHandler: (type: InstrumentHandlerType, callback: InstrumentHandlerCallback) => {
1617
if (type === 'error') {
1718
mockErrorCallback = callback;
1819
}
@@ -55,10 +56,10 @@ describe('registerErrorHandlers()', () => {
5556
const transaction = hub.startTransaction({ name: 'test' });
5657
expect(transaction.status).toBe(undefined);
5758

58-
mockErrorCallback();
59+
mockErrorCallback({});
5960
expect(transaction.status).toBe(undefined);
6061

61-
mockUnhandledRejectionCallback();
62+
mockUnhandledRejectionCallback({});
6263
expect(transaction.status).toBe(undefined);
6364
transaction.finish();
6465
});
@@ -68,7 +69,7 @@ describe('registerErrorHandlers()', () => {
6869
const transaction = hub.startTransaction({ name: 'test' });
6970
hub.configureScope(scope => scope.setSpan(transaction));
7071

71-
mockErrorCallback();
72+
mockErrorCallback({});
7273
expect(transaction.status).toBe('internal_error');
7374

7475
transaction.finish();
@@ -79,7 +80,7 @@ describe('registerErrorHandlers()', () => {
7980
const transaction = hub.startTransaction({ name: 'test' });
8081
hub.configureScope(scope => scope.setSpan(transaction));
8182

82-
mockUnhandledRejectionCallback();
83+
mockUnhandledRejectionCallback({});
8384
expect(transaction.status).toBe('internal_error');
8485
transaction.finish();
8586
});

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;
@@ -167,9 +169,9 @@ describe('IdleTransaction', () => {
167169
it('should record dropped transactions', async () => {
168170
const transaction = new IdleTransaction({ name: 'foo', startTimestamp: 1234, sampled: false }, hub, 1000);
169171

170-
const transport = hub.getClient()?.getTransport();
172+
const transport = hub.getClient()!.getTransport!();
171173

172-
const spy = jest.spyOn(transport!, 'recordLostEvent');
174+
const spy = jest.spyOn(transport, 'recordLostEvent');
173175

174176
transaction.initSpanRecorder(10);
175177
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)