Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ module.exports = {
rootDir: process.cwd(),
collectCoverage: true,
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.tsx$': 'ts-jest',
'^.+\\.ts$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.test.json',
},
],
'^.+\\.tsx$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.test.json',
},
],
},
coverageDirectory: '<rootDir>/coverage',
moduleFileExtensions: ['js', 'ts', 'tsx'],
testMatch: ['<rootDir>/**/*.test.ts', '<rootDir>/**/*.test.tsx'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.test.json',
},
__DEBUG_BUILD__: true,
},
testPathIgnorePatterns: ['<rootDir>/build/', '<rootDir>/node_modules/'],
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@size-limit/webpack": "~9.0.0",
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
"@types/chai": "^4.1.3",
"@types/jest": "^27.4.1",
"@types/jest": "^29.5.10",
"@types/jsdom": "^16.2.3",
"@types/mocha": "^5.2.0",
"@types/node": "~10.17.0",
Expand All @@ -106,8 +106,9 @@
"downlevel-dts": "~0.11.0",
"es-check": "7.1.0",
"eslint": "7.32.0",
"jest": "^27.5.1",
"jest-environment-node": "^27.5.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-node": "^29.7.0",
"jsdom": "^19.0.0",
"karma-browserstack-launcher": "^1.5.1",
"karma-firefox-launcher": "^1.1.0",
Expand All @@ -125,7 +126,7 @@
"rollup-plugin-terser": "^7.0.2",
"sinon": "^7.3.2",
"size-limit": "~9.0.0",
"ts-jest": "^27.1.4",
"ts-jest": "^29.1.1",
"ts-node": "10.9.1",
"typedoc": "^0.18.0",
"typescript": "4.9.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/test/errorhandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ describe('SentryErrorHandler', () => {
// this simulates the afterSend hook being called
client.cb({});

expect(showReportDialogSpy).toBeCalledTimes(1);
expect(showReportDialogSpy).toHaveBeenCalledTimes(1);
});

it('by just calling `showReportDialog` if hooks are not available', () => {
Expand All @@ -525,7 +525,7 @@ describe('SentryErrorHandler', () => {
const errorHandler = createErrorHandler({ showDialog: true });
errorHandler.handleError(new Error('test'));

expect(showReportDialogSpy).toBeCalledTimes(1);
expect(showReportDialogSpy).toHaveBeenCalledTimes(1);
});
});
});
Expand Down
12 changes: 7 additions & 5 deletions packages/angular/test/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as SentryBrowser from '@sentry/browser';
import type { BrowserTransportOptions } from '@sentry/browser/src/transports/types';
import type { Options } from '@sentry/types';

import { defaultIntegrations, init } from '../src/index';

Expand Down Expand Up @@ -26,19 +28,19 @@ describe('init', () => {

expect(browserInitSpy).toHaveBeenCalledTimes(1);

const options = browserInitSpy.mock.calls[0][0] || {};
expect(options.defaultIntegrations).not.toContainEqual(expect.objectContaining({ name: 'TryCatch' }));
const options = browserInitSpy.mock.calls[0][0] as Options<BrowserTransportOptions> | undefined;
expect(options?.defaultIntegrations).not.toContainEqual(expect.objectContaining({ name: 'TryCatch' }));
});

it.each([false as const, defaultIntegrations])(
"doesn't filter if `defaultIntegrations` is set to %s",
defaultIntegrations => {
(defaultIntegrations: Options<BrowserTransportOptions>['defaultIntegrations']) => {
init({ defaultIntegrations });

expect(browserInitSpy).toHaveBeenCalledTimes(1);

const options = browserInitSpy.mock.calls[0][0] || {};
expect(options.defaultIntegrations).toEqual(defaultIntegrations);
const options = browserInitSpy.mock.calls[0][0] as Options<BrowserTransportOptions> | undefined;
expect(options?.defaultIntegrations).toEqual(defaultIntegrations);
},
);
});
Expand Down
10 changes: 4 additions & 6 deletions packages/angular/test/tracing.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import type { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
import type { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, Routes } from '@angular/router';
import type { Hub } from '@sentry/types';

import { TraceClassDecorator, TraceDirective, TraceMethodDecorator, instrumentAngularRouting } from '../src';
Expand Down Expand Up @@ -99,10 +99,8 @@ describe('Angular Tracing', () => {
},
'/users/:id/',
],
])('%s', (_, routeSnapshot, expectedParams) => {
expect(getParameterizedRouteFromSnapshot(routeSnapshot as unknown as ActivatedRouteSnapshot)).toEqual(
expectedParams,
);
])('%s', (_: unknown, routeSnapshot: ActivatedRouteSnapshot, expectedParams: unknown) => {
expect(getParameterizedRouteFromSnapshot(routeSnapshot)).toEqual(expectedParams);
});
});

Expand Down Expand Up @@ -316,7 +314,7 @@ describe('Angular Tracing', () => {
},
],
],
])('%s and sets the source to `route`', async (_, url, result, routes) => {
])('%s and sets the source to `route`', async (_: unknown, url: string, result: string, routes: Routes) => {
const customStartTransaction = jest.fn(defaultStartTransaction);
const env = await TestEnv.setup({
customStartTransaction,
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ describe('SentryBrowser initialization', () => {
const sdkData = getClient()?.getOptions()._metadata?.sdk || {};

expect(sdkData.packages?.[0].name).toBe('cdn:@sentry/browser');
expect(utils.getSDKSource).toBeCalledTimes(1);
expect(utils.getSDKSource).toHaveBeenCalledTimes(1);
spy.mockRestore();
});

Expand Down
50 changes: 26 additions & 24 deletions packages/core/test/lib/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,8 +996,8 @@ describe('BaseClient', () => {
expect(TestClient.instance!.event).toBeUndefined();
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
// error, but because `beforeSend` returned `null`
expect(captureExceptionSpy).not.toBeCalled();
expect(loggerWarnSpy).toBeCalledWith('before send for type `error` returned `null`, will not send event.');
expect(captureExceptionSpy).not.toHaveBeenCalled();
expect(loggerWarnSpy).toHaveBeenCalledWith('before send for type `error` returned `null`, will not send event.');
});

test('calls `beforeSendTransaction` and discards the event', () => {
Expand All @@ -1015,8 +1015,10 @@ describe('BaseClient', () => {
expect(TestClient.instance!.event).toBeUndefined();
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
// error, but because `beforeSendTransaction` returned `null`
expect(captureExceptionSpy).not.toBeCalled();
expect(loggerWarnSpy).toBeCalledWith('before send for type `transaction` returned `null`, will not send event.');
expect(captureExceptionSpy).not.toHaveBeenCalled();
expect(loggerWarnSpy).toHaveBeenCalledWith(
'before send for type `transaction` returned `null`, will not send event.',
);
});

test('calls `beforeSend` and logs info about invalid return value', () => {
Expand All @@ -1034,7 +1036,7 @@ describe('BaseClient', () => {

expect(beforeSend).toHaveBeenCalled();
expect(TestClient.instance!.event).toBeUndefined();
expect(loggerWarnSpy).toBeCalledWith(
expect(loggerWarnSpy).toHaveBeenCalledWith(
new SentryError('before send for type `error` must return `null` or a valid event.'),
);
}
Expand All @@ -1055,7 +1057,7 @@ describe('BaseClient', () => {

expect(beforeSendTransaction).toHaveBeenCalled();
expect(TestClient.instance!.event).toBeUndefined();
expect(loggerWarnSpy).toBeCalledWith(
expect(loggerWarnSpy).toHaveBeenCalledWith(
new SentryError('before send for type `transaction` must return `null` or a valid event.'),
);
}
Expand Down Expand Up @@ -1317,8 +1319,8 @@ describe('BaseClient', () => {
expect(TestClient.instance!.event).toBeUndefined();
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
// error, but because the event processor returned `null`
expect(captureExceptionSpy).not.toBeCalled();
expect(loggerLogSpy).toBeCalledWith('An event processor returned `null`, will not send event.');
expect(captureExceptionSpy).not.toHaveBeenCalled();
expect(loggerLogSpy).toHaveBeenCalledWith('An event processor returned `null`, will not send event.');
});

test('event processor drops transaction event when it returns `null`', () => {
Expand All @@ -1335,8 +1337,8 @@ describe('BaseClient', () => {
expect(TestClient.instance!.event).toBeUndefined();
// This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
// error, but because the event processor returned `null`
expect(captureExceptionSpy).not.toBeCalled();
expect(loggerLogSpy).toBeCalledWith('An event processor returned `null`, will not send event.');
expect(captureExceptionSpy).not.toHaveBeenCalled();
expect(loggerLogSpy).toHaveBeenCalledWith('An event processor returned `null`, will not send event.');
});

test('event processor records dropped error events', () => {
Expand Down Expand Up @@ -1440,13 +1442,13 @@ describe('BaseClient', () => {
client.captureEvent({ message: 'hello' }, {}, scope);

expect(TestClient.instance!.event!.exception!.values![0]).toStrictEqual({ type: 'Error', value: 'sorry' });
expect(captureExceptionSpy).toBeCalledWith(exception, {
expect(captureExceptionSpy).toHaveBeenCalledWith(exception, {
data: {
__sentry__: true,
},
originalException: exception,
});
expect(loggerWarnSpy).toBeCalledWith(
expect(loggerWarnSpy).toHaveBeenCalledWith(
new SentryError(
`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.\nReason: ${exception}`,
),
Expand Down Expand Up @@ -1670,9 +1672,9 @@ describe('BaseClient', () => {
await undefined;
await undefined;

expect(mockSend).toBeCalledTimes(1);
expect(callback).toBeCalledTimes(1);
expect(callback).toBeCalledWith(errorEvent, {});
expect(mockSend).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(errorEvent, {});
});

it('emits `afterSendEvent` when sending a transaction', async () => {
Expand All @@ -1698,9 +1700,9 @@ describe('BaseClient', () => {
await undefined;
await undefined;

expect(mockSend).toBeCalledTimes(1);
expect(callback).toBeCalledTimes(1);
expect(callback).toBeCalledWith(transactionEvent, {});
expect(mockSend).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(transactionEvent, {});
});

it('still triggers `afterSendEvent` when transport.send rejects', async () => {
Expand Down Expand Up @@ -1730,9 +1732,9 @@ describe('BaseClient', () => {
await undefined;
await undefined;

expect(mockSend).toBeCalledTimes(1);
expect(callback).toBeCalledTimes(1);
expect(callback).toBeCalledWith(errorEvent, undefined);
expect(mockSend).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(errorEvent, undefined);
});

it('passes the response to the hook', async () => {
Expand Down Expand Up @@ -1762,9 +1764,9 @@ describe('BaseClient', () => {
await undefined;
await undefined;

expect(mockSend).toBeCalledTimes(1);
expect(callback).toBeCalledTimes(1);
expect(callback).toBeCalledWith(errorEvent, { statusCode: 200 });
expect(mockSend).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(errorEvent, { statusCode: 200 });
});
});

Expand Down
1 change: 0 additions & 1 deletion packages/deno/jest.config.js

This file was deleted.

19 changes: 15 additions & 4 deletions packages/gatsby/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ const baseConfig = require('../../jest/jest.config.js');

module.exports = {
...baseConfig,
setupFiles: ['<rootDir>/test/setEnvVars.ts'],
testEnvironment: 'jsdom',
preset: 'ts-jest/presets/js-with-ts',
transform: {
'^.+\\.js$': 'ts-jest',
...baseConfig.transform,
'^.+\\.ts$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.test.json',
},
],
'^.+\\.js$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.test.json',
},
],
},
setupFiles: ['<rootDir>/test/setEnvVars.ts'],
testEnvironment: 'jsdom',
};
8 changes: 4 additions & 4 deletions packages/gatsby/test/gatsby-browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('onClientEntry', () => {
onClientEntry(undefined, { plugins: [], dsn: 'dsn', release: 'release' });
// eslint-disable-next-line no-console
expect((console.warn as jest.Mock).mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"Sentry Logger [Warn]: The SDK was initialized in the Sentry config file, but options were found in the Gatsby config. These have been ignored. Merge them to the Sentry config if you want to use them.
Learn more about the Gatsby SDK in https://docs.sentry.io/platforms/javascript/guides/gatsby/.",
]
Expand All @@ -97,7 +97,7 @@ describe('onClientEntry', () => {
expect(console.warn).not.toHaveBeenCalled();
// eslint-disable-next-line no-console
expect((console.error as jest.Mock).mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"Sentry Logger [Error]: No config for the Gatsby SDK was found.
Learn how to configure it in https://docs.sentry.io/platforms/javascript/guides/gatsby/.",
]
Expand All @@ -112,9 +112,9 @@ describe('onClientEntry', () => {
expect(console.error).not.toHaveBeenCalled();
expect(sentryInit).toHaveBeenCalledTimes(1);
expect(sentryInit.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
{
"dsn": "dsn",
"plugins": Array [],
"plugins": [],
"release": "release",
}
`);
Expand Down
10 changes: 5 additions & 5 deletions packages/integrations/test/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Debug integration setup should register an event processor that', () =
testEventLogged(debugIntegration, testEvent);

expect(mockConsoleLog).toHaveBeenCalledTimes(1);
expect(mockConsoleLog).toBeCalledWith(testEvent);
expect(mockConsoleLog).toHaveBeenCalledWith(testEvent);
});

it('logs an event hint if available', () => {
Expand All @@ -64,8 +64,8 @@ describe('Debug integration setup should register an event processor that', () =
testEventLogged(debugIntegration, testEvent, testEventHint);

expect(mockConsoleLog).toHaveBeenCalledTimes(2);
expect(mockConsoleLog).toBeCalledWith(testEvent);
expect(mockConsoleLog).toBeCalledWith(testEventHint);
expect(mockConsoleLog).toHaveBeenCalledWith(testEvent);
expect(mockConsoleLog).toHaveBeenCalledWith(testEventHint);
});

it('logs events in stringified format when `stringify` option was set', () => {
Expand All @@ -75,7 +75,7 @@ describe('Debug integration setup should register an event processor that', () =
testEventLogged(debugIntegration, testEvent);

expect(mockConsoleLog).toHaveBeenCalledTimes(1);
expect(mockConsoleLog).toBeCalledWith(JSON.stringify(testEvent, null, 2));
expect(mockConsoleLog).toHaveBeenCalledWith(JSON.stringify(testEvent, null, 2));
});

it('logs event hints in stringified format when `stringify` option was set', () => {
Expand All @@ -87,6 +87,6 @@ describe('Debug integration setup should register an event processor that', () =
testEventLogged(debugIntegration, testEvent, testEventHint);

expect(mockConsoleLog).toHaveBeenCalledTimes(2);
expect(mockConsoleLog).toBeCalledWith(JSON.stringify(testEventHint, null, 2));
expect(mockConsoleLog).toHaveBeenCalledWith(JSON.stringify(testEventHint, null, 2));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ describe('Sentry webpack plugin config', () => {
});

it('errors when files are missing', () => {
expect(() => getUserConfigFile(tempDir, 'server')).toThrowError(
expect(() => getUserConfigFile(tempDir, 'server')).toThrow(
`Cannot find 'sentry.server.config.ts' or 'sentry.server.config.js' in '${tempDir}'`,
);
expect(() => getUserConfigFile(tempDir, 'client')).toThrowError(
expect(() => getUserConfigFile(tempDir, 'client')).toThrow(
`Cannot find 'sentry.client.config.ts' or 'sentry.client.config.js' in '${tempDir}'`,
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/node/test/integrations/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('tracing', () => {
() => hub,
);

expect(loggerLogSpy).toBeCalledWith('HTTP Integration is skipped because of instrumenter configuration.');
expect(loggerLogSpy).toHaveBeenCalledWith('HTTP Integration is skipped because of instrumenter configuration.');
});

it('omits query and fragment from description and adds to span data instead', () => {
Expand Down
Loading