Skip to content

Commit 4c4b2af

Browse files
committed
ref(core): Adjust test mocks
1 parent feeff81 commit 4c4b2af

File tree

3 files changed

+66
-79
lines changed

3 files changed

+66
-79
lines changed

packages/core/test/mocks/backend.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

packages/core/test/mocks/client.ts

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,77 @@
1+
import { Options, EventHint, Event, Session, SeverityLevel, Transport } from '@sentry/types';
2+
13
import { BaseClient } from '../../src/baseclient';
24
import { initAndBind } from '../../src/sdk';
3-
import { TestBackend, TestOptions } from './backend';
5+
import { resolvedSyncPromise } from '@sentry/utils';
6+
7+
interface TestOptions extends Options {
8+
test?: boolean;
9+
mockInstallFailure?: boolean;
10+
enableSend?: boolean;
11+
}
412

5-
export class TestClient extends BaseClient<TestBackend, TestOptions> {
13+
export class TestClient extends BaseClient<TestOptions> {
614
public static instance?: TestClient;
15+
public static sendEventCalled?: (event: Event) => void;
16+
17+
public event?: Event;
18+
public session?: Session;
719

820
public constructor(options: TestOptions) {
9-
super(TestBackend, options);
21+
super(options);
1022
TestClient.instance = this;
1123
}
24+
25+
public sendEvent(event: Event): void {
26+
this.event = event;
27+
if (this._options.enableSend) {
28+
super.sendEvent(event);
29+
return;
30+
}
31+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
32+
TestClient.sendEventCalled && TestClient.sendEventCalled(event);
33+
}
34+
35+
public sendSession(session: Session): void {
36+
this.session = session;
37+
}
38+
39+
protected _setupTransport(): Transport {
40+
if (!this._options.dsn) {
41+
// We return the noop transport here in case there is no Dsn.
42+
return super._setupTransport();
43+
}
44+
45+
const transportOptions = this._options.transportOptions
46+
? this._options.transportOptions
47+
: { dsn: this._options.dsn };
48+
49+
if (this._options.transport) {
50+
return new this._options.transport(transportOptions);
51+
}
52+
53+
return super._setupTransport();
54+
}
55+
56+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
57+
protected _eventFromException(exception: any, _hint?: EventHint): PromiseLike<Event> {
58+
return resolvedSyncPromise({
59+
exception: {
60+
values: [
61+
{
62+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
63+
type: exception.name,
64+
value: exception.message,
65+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
66+
},
67+
],
68+
},
69+
});
70+
}
71+
72+
protected _eventFromMessage(message: string, level: SeverityLevel = 'info'): PromiseLike<Event> {
73+
return resolvedSyncPromise({ message, level });
74+
}
1275
}
1376

1477
export function init(options: TestOptions): void {

packages/node/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export {
3939
} from '@sentry/core';
4040

4141
export { NodeOptions } from './types';
42-
export { NodeBackend } from './backend';
4342
export { NodeClient } from './client';
4443
export { defaultIntegrations, init, lastEventId, flush, close, getSentryRelease } from './sdk';
4544
export { deepReadDirSync } from './utils';

0 commit comments

Comments
 (0)