Skip to content

Commit 4357b44

Browse files
authored
test: Clean up test output warnings (#14358)
This PR cleans up some jest test output: 1. Ensure we do avoid printing out some `console.error` stuff for invalid DSN parsing. 2. Update jest config to avoid printing of these warnings you get all the time in the tests: ``` ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ```
1 parent da5b2e0 commit 4357b44

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

jest/jest.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ module.exports = {
33
rootDir: process.cwd(),
44
collectCoverage: true,
55
transform: {
6-
'^.+\\.ts$': 'ts-jest',
7-
'^.+\\.tsx$': 'ts-jest',
6+
'^.+\\.(ts|tsx)$': 'ts-jest',
87
},
98
coverageDirectory: '<rootDir>/coverage',
109
moduleFileExtensions: ['js', 'ts', 'tsx'],
@@ -15,6 +14,10 @@ module.exports = {
1514
globals: {
1615
'ts-jest': {
1716
tsconfig: '<rootDir>/tsconfig.test.json',
17+
diagnostics: {
18+
// Ignore this warning for tests, we do not care about this
19+
ignoreCodes: ['TS151001'],
20+
},
1821
},
1922
__DEBUG_BUILD__: true,
2023
},

packages/core/test/lib/envelope.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ describe('createSpanEnvelope', () => {
9595
client = new TestClient(options);
9696
setCurrentClient(client);
9797
client.init();
98+
99+
// We want to avoid console errors in the tests
100+
jest.spyOn(console, 'error').mockImplementation(() => {});
101+
});
102+
103+
afterEach(() => {
104+
jest.resetAllMocks();
98105
});
99106

100107
it('creates a span envelope', () => {

packages/core/test/lib/metrics/browser-aggregator.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { CounterMetric } from '../../../src/metrics/instance';
33
import { serializeMetricBuckets } from '../../../src/metrics/utils';
44
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';
55

6+
function _cleanupAggregator(aggregator: BrowserMetricsAggregator): void {
7+
clearInterval(aggregator['_interval']);
8+
}
9+
610
describe('BrowserMetricsAggregator', () => {
711
const options = getDefaultTestClientOptions({ tracesSampleRate: 0.0 });
812
const testClient = new TestClient(options);
@@ -21,6 +25,8 @@ describe('BrowserMetricsAggregator', () => {
2125
timestamp: expect.any(Number),
2226
unit: 'none',
2327
});
28+
29+
_cleanupAggregator(aggregator);
2430
});
2531

2632
it('groups same items together', () => {
@@ -40,6 +46,8 @@ describe('BrowserMetricsAggregator', () => {
4046
unit: 'none',
4147
});
4248
expect(firstValue.metric._value).toEqual(2);
49+
50+
_cleanupAggregator(aggregator);
4351
});
4452

4553
it('differentiates based on tag value', () => {
@@ -48,6 +56,8 @@ describe('BrowserMetricsAggregator', () => {
4856
expect(aggregator['_buckets'].size).toEqual(1);
4957
aggregator.add('g', 'cpu', 55, undefined, { a: 'value' });
5058
expect(aggregator['_buckets'].size).toEqual(2);
59+
60+
_cleanupAggregator(aggregator);
5161
});
5262

5363
describe('serializeBuckets', () => {
@@ -69,6 +79,8 @@ describe('BrowserMetricsAggregator', () => {
6979
expect(serializedBuckets).toContain('cpu@none:52:50:55:157:3|g|T');
7080
expect(serializedBuckets).toContain('lcp@second:1:1.2|d|#a:value,b:anothervalue|T');
7181
expect(serializedBuckets).toContain('important_people@none:97:98|s|#numericKey:2|T');
82+
83+
_cleanupAggregator(aggregator);
7284
});
7385
});
7486
});

packages/nextjs/test/utils/tunnelRoute.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ describe('applyTunnelRouteOption()', () => {
3434
});
3535

3636
it("Doesn't apply `tunnelRoute` when DSN is invalid", () => {
37+
// Avoid polluting the test output with error messages
38+
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
39+
3740
globalWithInjectedValues._sentryRewritesTunnelPath = '/my-error-monitoring-route';
3841
const options: any = {
3942
dsn: 'invalidDsn',
@@ -42,6 +45,8 @@ describe('applyTunnelRouteOption()', () => {
4245
applyTunnelRouteOption(options);
4346

4447
expect(options.tunnel).toBeUndefined();
48+
49+
mockConsoleError.mockRestore();
4550
});
4651

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

0 commit comments

Comments
 (0)