Skip to content

Commit 4893f9f

Browse files
committed
adjust test client
1 parent 76a6edb commit 4893f9f

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

packages/core/test/mocks/client.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Session } from '@sentry/hub';
2-
import { Event, Integration, Options, Severity, SeverityLevel, Transport } from '@sentry/types';
3-
import { resolvedSyncPromise } from '@sentry/utils';
2+
import { Event, Integration, Options, Severity, SeverityLevel, NewTransport, EventStatus } from '@sentry/types';
3+
import { resolvedSyncPromise, resolve } from '@sentry/utils';
44

55
import { BaseClient } from '../../src/baseclient';
66
import { initAndBind } from '../../src/sdk';
7-
import { NewTransport } from '../../src/transports/base';
8-
import { NoopTransport } from '../../src/transports/noop';
7+
98
export interface TestOptions extends Options {
109
test?: boolean;
1110
mockInstallFailure?: boolean;
@@ -20,8 +19,8 @@ export class TestClient extends BaseClient<TestOptions> {
2019
public event?: Event;
2120
public session?: Session;
2221

23-
public constructor(options: TestOptions, transport: Transport, newTransport?: NewTransport) {
24-
super(options, transport, newTransport);
22+
public constructor(options: TestOptions, transport: NewTransport) {
23+
super(options, transport);
2524
TestClient.instance = this;
2625
}
2726

@@ -64,22 +63,27 @@ export class TestClient extends BaseClient<TestOptions> {
6463
}
6564
}
6665

67-
export function init(options: TestOptions, transport: Transport, newTransport?: NewTransport): void {
68-
initAndBind(TestClient, options, transport, newTransport);
66+
export function init(options: TestOptions, transport: NewTransport): void {
67+
initAndBind(TestClient, options, transport);
6968
}
7069

71-
export function setupTestTransport(options: TestOptions): { transport: Transport; newTransport?: NewTransport } {
72-
const noop = { transport: new NoopTransport() };
70+
export function setupTestTransport(options: TestOptions): NewTransport {
71+
const noop = {
72+
send: () =>
73+
resolvedSyncPromise({
74+
reason: 'NoopTransport: Event has been skipped because no Dsn is configured.',
75+
status: 'skipped' as EventStatus,
76+
}),
77+
flush: () => resolvedSyncPromise(true),
78+
};
7379

7480
if (!options.dsn) {
7581
// We return the noop transport here in case there is no Dsn.
7682
return noop;
7783
}
7884

79-
const transportOptions = options.transportOptions ? options.transportOptions : { dsn: options.dsn };
80-
8185
if (options.transport) {
82-
return { transport: new this._options.transport(transportOptions) };
86+
return this._options.transport;
8387
}
8488

8589
return noop;

0 commit comments

Comments
 (0)