Skip to content
Merged
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
7 changes: 5 additions & 2 deletions jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module.exports = {
rootDir: process.cwd(),
collectCoverage: true,
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.tsx$': 'ts-jest',
'^.+\\.(ts|tsx)$': 'ts-jest',
},
coverageDirectory: '<rootDir>/coverage',
moduleFileExtensions: ['js', 'ts', 'tsx'],
Expand All @@ -15,6 +14,10 @@ module.exports = {
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.test.json',
diagnostics: {
// Ignore this warning for tests, we do not care about this
ignoreCodes: ['TS151001'],
},
},
__DEBUG_BUILD__: true,
},
Expand Down
7 changes: 7 additions & 0 deletions packages/core/test/lib/envelope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ describe('createSpanEnvelope', () => {
client = new TestClient(options);
setCurrentClient(client);
client.init();

// We want to avoid console errors in the tests
jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
jest.resetAllMocks();
});

it('creates a span envelope', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/core/test/lib/metrics/browser-aggregator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { CounterMetric } from '../../../src/metrics/instance';
import { serializeMetricBuckets } from '../../../src/metrics/utils';
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';

function _cleanupAggregator(aggregator: BrowserMetricsAggregator): void {
clearInterval(aggregator['_interval']);
}

describe('BrowserMetricsAggregator', () => {
const options = getDefaultTestClientOptions({ tracesSampleRate: 0.0 });
const testClient = new TestClient(options);
Expand All @@ -21,6 +25,8 @@ describe('BrowserMetricsAggregator', () => {
timestamp: expect.any(Number),
unit: 'none',
});

_cleanupAggregator(aggregator);
});

it('groups same items together', () => {
Expand All @@ -40,6 +46,8 @@ describe('BrowserMetricsAggregator', () => {
unit: 'none',
});
expect(firstValue.metric._value).toEqual(2);

_cleanupAggregator(aggregator);
});

it('differentiates based on tag value', () => {
Expand All @@ -48,6 +56,8 @@ describe('BrowserMetricsAggregator', () => {
expect(aggregator['_buckets'].size).toEqual(1);
aggregator.add('g', 'cpu', 55, undefined, { a: 'value' });
expect(aggregator['_buckets'].size).toEqual(2);

_cleanupAggregator(aggregator);
});

describe('serializeBuckets', () => {
Expand All @@ -69,6 +79,8 @@ describe('BrowserMetricsAggregator', () => {
expect(serializedBuckets).toContain('cpu@none:52:50:55:157:3|g|T');
expect(serializedBuckets).toContain('lcp@second:1:1.2|d|#a:value,b:anothervalue|T');
expect(serializedBuckets).toContain('important_people@none:97:98|s|#numericKey:2|T');

_cleanupAggregator(aggregator);
});
});
});
5 changes: 5 additions & 0 deletions packages/nextjs/test/utils/tunnelRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe('applyTunnelRouteOption()', () => {
});

it("Doesn't apply `tunnelRoute` when DSN is invalid", () => {
// Avoid polluting the test output with error messages
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {});

globalWithInjectedValues._sentryRewritesTunnelPath = '/my-error-monitoring-route';
const options: any = {
dsn: 'invalidDsn',
Expand All @@ -42,6 +45,8 @@ describe('applyTunnelRouteOption()', () => {
applyTunnelRouteOption(options);

expect(options.tunnel).toBeUndefined();

mockConsoleError.mockRestore();
});

it("Doesn't apply `tunnelRoute` option when `tunnelRoute` option wasn't injected", () => {
Expand Down
Loading