Skip to content

Commit 7c00a17

Browse files
committed
fix type errors in integrations tests
1 parent c12ff03 commit 7c00a17

File tree

8 files changed

+67
-61
lines changed

8 files changed

+67
-61
lines changed

packages/integrations/test/captureconsole.test.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Event, Integration } from '@sentry/types';
1+
/* eslint-disable @typescript-eslint/unbound-method */
2+
import { Event, Hub, Integration } from '@sentry/types';
23

34
import { CaptureConsole } from '../src/captureconsole';
45

@@ -16,10 +17,11 @@ const mockHub = {
1617
captureException: jest.fn(),
1718
};
1819

19-
const getMockHubWithIntegration = (integration: Integration) => ({
20-
...mockHub,
21-
getIntegration: jest.fn(() => integration),
22-
});
20+
const getMockHubWithIntegration = (integration: Integration) =>
21+
({
22+
...mockHub,
23+
getIntegration: jest.fn(() => integration),
24+
} as unknown as Hub);
2325

2426
// We're using this to un-monkey patch the console after each test.
2527
const originalConsole = Object.assign({}, global.console);
@@ -36,7 +38,7 @@ describe('CaptureConsole setup', () => {
3638
const captureConsoleIntegration = new CaptureConsole({ levels: ['log', 'warn'] });
3739
captureConsoleIntegration.setupOnce(
3840
() => undefined,
39-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
41+
() => getMockHubWithIntegration(captureConsoleIntegration),
4042
);
4143

4244
expect(global.console.error).toBe(originalConsole.error); // not monkey patched
@@ -48,7 +50,7 @@ describe('CaptureConsole setup', () => {
4850
const captureConsoleIntegration = new CaptureConsole();
4951
captureConsoleIntegration.setupOnce(
5052
() => undefined,
51-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
53+
() => getMockHubWithIntegration(captureConsoleIntegration),
5254
);
5355

5456
// expect a set of defined console levels to have been monkey patched
@@ -68,7 +70,7 @@ describe('CaptureConsole setup', () => {
6870
const captureConsoleIntegration = new CaptureConsole({ levels: [] });
6971
captureConsoleIntegration.setupOnce(
7072
() => undefined,
71-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
73+
() => getMockHubWithIntegration(captureConsoleIntegration),
7274
);
7375

7476
// expect the default set of console levels not to have been monkey patched
@@ -93,7 +95,7 @@ describe('CaptureConsole setup', () => {
9395
const captureConsoleIntegration = new CaptureConsole();
9496
captureConsoleIntegration.setupOnce(
9597
() => undefined,
96-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
98+
() => getMockHubWithIntegration(captureConsoleIntegration),
9799
);
98100
}).not.toThrow();
99101

@@ -105,7 +107,7 @@ describe('CaptureConsole setup', () => {
105107
const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
106108
captureConsoleIntegration.setupOnce(
107109
() => undefined,
108-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
110+
() => getMockHubWithIntegration(captureConsoleIntegration),
109111
);
110112

111113
// call a wrapped function
@@ -119,7 +121,7 @@ describe('CaptureConsole setup', () => {
119121
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
120122
captureConsoleIntegration.setupOnce(
121123
() => undefined,
122-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
124+
() => getMockHubWithIntegration(captureConsoleIntegration),
123125
);
124126

125127
// call a wrapped function
@@ -135,7 +137,7 @@ describe('CaptureConsole setup', () => {
135137
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
136138
captureConsoleIntegration.setupOnce(
137139
() => undefined,
138-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
140+
() => getMockHubWithIntegration(captureConsoleIntegration),
139141
);
140142

141143
// call a wrapped function
@@ -154,7 +156,7 @@ describe('CaptureConsole setup', () => {
154156
const captureConsoleIntegration = new CaptureConsole({ levels: ['assert'] });
155157
captureConsoleIntegration.setupOnce(
156158
() => undefined,
157-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
159+
() => getMockHubWithIntegration(captureConsoleIntegration),
158160
);
159161

160162
global.console.assert(1 + 1 === 3);
@@ -168,7 +170,7 @@ describe('CaptureConsole setup', () => {
168170
const captureConsoleIntegration = new CaptureConsole({ levels: ['assert'] });
169171
captureConsoleIntegration.setupOnce(
170172
() => undefined,
171-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
173+
() => getMockHubWithIntegration(captureConsoleIntegration),
172174
);
173175

174176
global.console.assert(1 + 1 === 3, 'expression is false');
@@ -182,7 +184,7 @@ describe('CaptureConsole setup', () => {
182184
const captureConsoleIntegration = new CaptureConsole({ levels: ['assert'] });
183185
captureConsoleIntegration.setupOnce(
184186
() => undefined,
185-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
187+
() => getMockHubWithIntegration(captureConsoleIntegration),
186188
);
187189

188190
global.console.assert(1 + 1 === 2);
@@ -192,7 +194,7 @@ describe('CaptureConsole setup', () => {
192194
const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
193195
captureConsoleIntegration.setupOnce(
194196
() => undefined,
195-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
197+
() => getMockHubWithIntegration(captureConsoleIntegration),
196198
);
197199

198200
const someError = new Error('some error');
@@ -206,7 +208,7 @@ describe('CaptureConsole setup', () => {
206208
const captureConsoleIntegration = new CaptureConsole();
207209
captureConsoleIntegration.setupOnce(
208210
() => undefined,
209-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
211+
() => getMockHubWithIntegration(captureConsoleIntegration),
210212
);
211213

212214
const someError = new Error('some error');
@@ -220,7 +222,7 @@ describe('CaptureConsole setup', () => {
220222
const captureConsoleIntegration = new CaptureConsole();
221223
captureConsoleIntegration.setupOnce(
222224
() => undefined,
223-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
225+
() => getMockHubWithIntegration(captureConsoleIntegration),
224226
);
225227

226228
global.console.error('some message');
@@ -233,7 +235,7 @@ describe('CaptureConsole setup', () => {
233235
const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
234236
captureConsoleIntegration.setupOnce(
235237
() => undefined,
236-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
238+
() => getMockHubWithIntegration(captureConsoleIntegration),
237239
);
238240

239241
global.console.error('some non-error message');
@@ -247,7 +249,7 @@ describe('CaptureConsole setup', () => {
247249
const captureConsoleIntegration = new CaptureConsole({ levels: ['info'] });
248250
captureConsoleIntegration.setupOnce(
249251
() => undefined,
250-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
252+
() => getMockHubWithIntegration(captureConsoleIntegration),
251253
);
252254

253255
global.console.info('some message');
@@ -265,7 +267,7 @@ describe('CaptureConsole setup', () => {
265267
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
266268
captureConsoleIntegration.setupOnce(
267269
() => undefined,
268-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
270+
() => getMockHubWithIntegration(captureConsoleIntegration),
269271
);
270272

271273
global.console.log('some message 1', 'some message 2');
@@ -281,11 +283,11 @@ describe('CaptureConsole setup', () => {
281283
const captureConsoleIntegration = new CaptureConsole({ levels: ['log', 'someNonExistingLevel', 'error'] });
282284
captureConsoleIntegration.setupOnce(
283285
() => undefined,
284-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
286+
() => getMockHubWithIntegration(captureConsoleIntegration),
285287
);
286288

287289
// The provided level should not be created
288-
expect(global.console['someNonExistingLevel']).toBeUndefined();
290+
expect((global.console as any)['someNonExistingLevel']).toBeUndefined();
289291

290292
// Ohter levels should be wrapped as expected
291293
expect(global.console.log).not.toBe(originalConsole.log);
@@ -296,7 +298,7 @@ describe('CaptureConsole setup', () => {
296298
const captureConsoleIntegration = new CaptureConsole({ levels: ['log', 'error'] });
297299
captureConsoleIntegration.setupOnce(
298300
() => undefined,
299-
() => getMockHubWithIntegration(null) as any, // simulate not having the integration registered
301+
() => getMockHubWithIntegration(null as any), // simulate not having the integration registered
300302
);
301303

302304
// Console should be wrapped
@@ -310,12 +312,12 @@ describe('CaptureConsole setup', () => {
310312

311313
it("should not crash when the original console methods don't exist at time of invocation", () => {
312314
const originalConsoleLog = global.console.log;
313-
global.console.log = undefined; // don't `delete` here, otherwise `fill` won't wrap the function
315+
global.console.log = undefined as any; // don't `delete` here, otherwise `fill` won't wrap the function
314316

315317
const captureConsoleIntegration = new CaptureConsole({ levels: ['log'] });
316318
captureConsoleIntegration.setupOnce(
317319
() => undefined,
318-
() => getMockHubWithIntegration(captureConsoleIntegration) as any,
320+
() => getMockHubWithIntegration(captureConsoleIntegration),
319321
);
320322

321323
expect(() => {

packages/integrations/test/debug.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const mockGetCurrentHub = (getIntegrationResult: Integration) => ({
88

99
// Replace console log with a mock so we can check for invocations
1010
const mockConsoleLog = jest.fn();
11+
// eslint-disable-next-line @typescript-eslint/unbound-method
1112
const originalConsoleLog = global.console.log;
1213
global.console.log = mockConsoleLog;
1314

packages/integrations/test/dedupe.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import { Event } from '@sentry/types';
1+
import { Event as SentryEvent, Exception, StackFrame, Stacktrace } from '@sentry/types';
22

33
import { _shouldDropEvent } from '../src/dedupe';
44

5+
type EventWithException = SentryEvent & {
6+
exception: {
7+
values: ExceptionWithStacktrace[];
8+
};
9+
};
10+
type ExceptionWithStacktrace = Exception & { stacktrace: StacktraceWithFrames };
11+
type StacktraceWithFrames = Stacktrace & { frames: StackFrame[] };
12+
513
/** JSDoc */
614
function clone<T>(data: T): T {
715
return JSON.parse(JSON.stringify(data));
816
}
917

10-
const messageEvent: Event = {
18+
const messageEvent: EventWithException = {
1119
fingerprint: ['MrSnuffles'],
1220
message: 'PickleRick',
1321
exception: {
@@ -34,7 +42,7 @@ const messageEvent: Event = {
3442
],
3543
},
3644
};
37-
const exceptionEvent: Event = {
45+
const exceptionEvent: EventWithException = {
3846
exception: {
3947
values: [
4048
{

packages/integrations/test/extraerrordata.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('ExtraErrorData()', () => {
7171
event = {
7272
// @ts-ignore Allow contexts on event
7373
contexts: {
74-
foo: 42,
74+
foo: { bar: 42 },
7575
},
7676
};
7777
const error = new TypeError('foo') as ExtendedError;
@@ -85,7 +85,7 @@ describe('ExtraErrorData()', () => {
8585
TypeError: {
8686
baz: 42,
8787
},
88-
foo: 42,
88+
foo: { bar: 42 },
8989
});
9090
});
9191

packages/integrations/test/offline.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function initIntegration(options: { maxStoredEvents?: number } = {}): void {
169169
jest.spyOn(utils, 'getGlobalObject').mockImplementation(
170170
() =>
171171
({
172-
addEventListener: (_windowEvent, callback) => {
172+
addEventListener: (_windowEvent: any, callback: any) => {
173173
eventListeners.push(callback);
174174
},
175175
navigator: {

0 commit comments

Comments
 (0)