Skip to content

Commit de3e675

Browse files
committed
switch to console error
1 parent 78468e3 commit de3e675

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

packages/core/test/lib/base.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('BaseClient', () => {
7777
expect(client.getTransport()).toBeUndefined();
7878
});
7979

80-
test('allows being passed an invalid Dsn', () => {
80+
test('handles being passed an invalid Dsn', () => {
8181
const options = getDefaultTestClientOptions({ dsn: 'abc' });
8282
const client = new TestClient(options);
8383

packages/utils/src/dsn.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
22

3-
import { SentryError } from './error';
43
import { logger } from './logger';
54

65
/** Regular expression used to parse a Dsn. */
@@ -37,7 +36,9 @@ export function dsnFromString(str: string): DsnComponents | undefined {
3736
const match = DSN_REGEX.exec(str);
3837

3938
if (!match) {
40-
logger.error(`Invalid Sentry Dsn: ${str}`);
39+
// This should be logged to the console
40+
// eslint-disable-next-line no-console
41+
console.error(`Invalid Sentry Dsn: ${str}`);
4142
return undefined;
4243
}
4344

packages/utils/test/dsn.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ function testIf(condition: boolean): jest.It {
55
return condition ? test : test.skip;
66
}
77

8-
const loggerSpy = jest.spyOn(logger, 'error').mockImplementation(() => {});
8+
const loggerErrorSpy = jest.spyOn(logger, 'error').mockImplementation(() => {});
9+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
910

1011
describe('Dsn', () => {
1112
beforeEach(() => {
12-
loggerSpy.mockClear();
13+
jest.clearAllMocks();
1314
});
1415

1516
describe('fromComponents', () => {
@@ -81,7 +82,7 @@ describe('Dsn', () => {
8182
}),
8283
).toBeUndefined();
8384

84-
expect(logger.error).toHaveBeenCalledTimes(4);
85+
expect(loggerErrorSpy).toHaveBeenCalledTimes(4);
8586
});
8687

8788
testIf(__DEBUG_BUILD__)('returns `undefined` if components are invalid', () => {
@@ -103,7 +104,7 @@ describe('Dsn', () => {
103104
}),
104105
).toBeUndefined();
105106

106-
expect(logger.error).toHaveBeenCalledTimes(2);
107+
expect(loggerErrorSpy).toHaveBeenCalledTimes(2);
107108
});
108109
});
109110

@@ -165,22 +166,23 @@ describe('Dsn', () => {
165166

166167
testIf(__DEBUG_BUILD__)('returns undefined when provided invalid Dsn', () => {
167168
expect(makeDsn('some@random.dsn')).toBeUndefined();
168-
expect(logger.error).toHaveBeenCalledTimes(1);
169+
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
169170
});
170171

171172
testIf(__DEBUG_BUILD__)('returns undefined if mandatory fields are missing', () => {
172173
expect(makeDsn('://abc@sentry.io/123')).toBeUndefined();
173174
expect(makeDsn('https://@sentry.io/123')).toBeUndefined();
174175
expect(makeDsn('https://abc@123')).toBeUndefined();
175176
expect(makeDsn('https://abc@sentry.io/')).toBeUndefined();
176-
expect(logger.error).toHaveBeenCalledTimes(4);
177+
expect(consoleErrorSpy).toHaveBeenCalledTimes(4);
177178
});
178179

179180
testIf(__DEBUG_BUILD__)('returns undefined if fields are invalid', () => {
180181
expect(makeDsn('httpx://abc@sentry.io/123')).toBeUndefined();
181182
expect(makeDsn('httpx://abc@sentry.io:xxx/123')).toBeUndefined();
182183
expect(makeDsn('http://abc@sentry.io/abc')).toBeUndefined();
183-
expect(logger.error).toHaveBeenCalledTimes(3);
184+
expect(loggerErrorSpy).toHaveBeenCalledTimes(2);
185+
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
184186
});
185187
});
186188

0 commit comments

Comments
 (0)