8000 build(tracing-internal): Remove circular dependency (#7608) · lapa182/sentry-javascript@dce26c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit dce26c9

Browse files
authored
build(tracing-internal): Remove circular dependency (getsentry#7608)
No need to depend on @sentry/browser as devDependency, which Nx complains about. I copied the TestClient from Replay, where we had the same issue.
1 parent b830f87 commit dce26c9

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

packages/tracing-internal/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"tslib": "^1.9.3"
2323
},
2424
"devDependencies": {
25-
"@sentry/browser": "7.45.0",
2625
"@types/express": "^4.17.14"
2726
},
2827
"scripts": {

packages/tracing-internal/test/browser/backgroundtab.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { BrowserClient } from '@sentry/browser';
21
import { Hub, makeMain } from '@sentry/core';
32
import { JSDOM } from 'jsdom';
43

54
import { addExtensionMethods } from '../../../tracing/src';
65
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
76
import { registerBackgroundTabDetection } from '../../src/browser/backgroundtab';
7+
import { TestClient } from '../utils/TestClient';
88

99
describe('registerBackgroundTabDetection', () => {
1010
let events: Record<string, any> = {};
@@ -15,7 +15,7 @@ describe('registerBackgroundTabDetection', () => {
1515
global.document = dom.window.document;
1616

1717
const options = getDefaultBrowserClientOptions({ tracesSampleRate: 1 });
18-
hub = new Hub(new BrowserClient(options));
18+
hub = new Hub(new TestClient(options));
1919
makeMain(hub);
2020

2121
// If we do not add extension methods, invoking hub.startTransaction returns undefined

packages/tracing-internal/test/browser/browsertracing.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BrowserClient, WINDOW } from '@sentry/browser';
21
import { Hub, makeMain, TRACING_DEFAULTS } from '@sentry/core';
32
import * as hubExtensions from '@sentry/core';
43
import type { BaseTransportOptions, ClientOptions, DsnComponents } from '@sentry/types';
@@ -12,6 +11,8 @@ import type { BrowserTracingOptions } from '../../src/browser/browsertracing';
1211
import { BrowserTracing, getMetaContent } from '../../src/browser/browsertracing';
1312
import { defaultRequestInstrumentationOptions } from '../../src/browser/request';
1413
import { instrumentRoutingWithDefaults } from '../../src/browser/router';
14+
import { WINDOW } from '../../src/browser/types';
15+
import { TestClient } from '../utils/TestClient';
1516

1617
let mockChangeHistory: ({ to, from }: { to: string; from?: string }) => void = () => undefined;
1718

@@ -61,7 +62,7 @@ describe('BrowserTracing', () => {
6162
beforeEach(() => {
6263
jest.useFakeTimers();
6364
const options = getDefaultBrowserClientOptions({ tracesSampleRate: 1 });
64-
hub = new Hub(new BrowserClient(options));
65+
hub = new Hub(new TestClient(options));
6566
makeMain(hub);
6667
document.head.innerHTML = '';
6768

@@ -599,7 +600,7 @@ describe('BrowserTracing', () => {
599600

600601
const tracesSampler = jest.fn();
601602
const options = getDefaultBrowserClientOptions({ tracesSampler });
602-
hub.bindClient(new BrowserClient(options));
603+
hub.bindClient(new TestClient(options));
603604
// setting up the BrowserTracing integration automatically starts a pageload transaction
604605
createBrowserTracing(true);
605606

@@ -616,7 +617,7 @@ describe('BrowserTracing', () => {
616617

617618
const tracesSampler = jest.fn();
618619
const options = getDefaultBrowserClientOptions({ tracesSampler });
619-
hub.bindClient(new BrowserClient(options));
620+
hub.bindClient(new TestClient(options));
620621
// setting up the BrowserTracing integration normally automatically starts a pageload transaction, but that's not
621622
// what we're testing here
622623
createBrowserTracing(true, { startTransactionOnPageLoad: false });

packages/tracing-internal/test/browser/request.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BrowserClient } from '@sentry/browser';
21
import * as sentryCore from '@sentry/core';
32
import * as utils from '@sentry/utils';
43

@@ -7,6 +6,7 @@ import { addExtensionMethods, Span, spanStatusfromHttpCode } from '../../../trac
76
import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils';
87
import type { FetchData, XHRData } from '../../src/browser/request';
98
import { fetchCallback, instrumentOutgoingRequests, shouldAttachHeaders, xhrCallback } from '../../src/browser/request';
9+
import { TestClient } from '../utils/TestClient';
1010

1111
beforeAll(() => {
1212
addExtensionMethods();
@@ -54,7 +54,7 @@ describe('callbacks', () => {
5454

5555
beforeAll(() => {
5656
const options = getDefaultBrowserClientOptions({ tracesSampleRate: 1 });
57-
hub = new sentryCore.Hub(new BrowserClient(options));
57+
hub = new sentryCore.Hub(new TestClient(options));
5858
sentryCore.makeMain(hub);
5959
});
6060

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { BaseClient, createTransport, initAndBind } from '@sentry/core';
2+
import type { BrowserClientReplayOptions, ClientOptions, Event, SeverityLevel } from '@sentry/types';
3+
import { resolvedSyncPromise } from '@sentry/utils';
4+
5+
export interface TestClientOptions extends ClientOptions, BrowserClientReplayOptions {}
6+
7+
export class TestClient extends BaseClient<TestClientOptions> {
8+
public constructor(options: TestClientOptions) {
9+
super(options);
10+
}
11+
12+
public eventFromException(exception: any): PromiseLike<Event> {
13+
return resolvedSyncPromise({
14+
exception: {
15+
values: [
16+
{
17+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
18+
type: exception.name,
19+
value: exception.message,
20+
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
21+
},
22+
],
23+
},
24+
});
25+
}
26+
27+
public eventFromMessage(message: string, level: SeverityLevel = 'info'): PromiseLike<Event> {
28+
return resolvedSyncPromise({ message, level });
29+
}
30+
}
31+
32+
export function init(options: TestClientOptions): void {
33+
initAndBind(TestClient, options);
34+
}
35+
36+
export function getDefaultClientOptions(options: Partial<ClientOptions> = {}): ClientOptions {
37+
return {
38+
integrations: [],
39+
dsn: 'https://username@domain/123',
40+
transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => resolvedSyncPromise({})),
41+
stackParser: () => [],
42+
...options,
43+
};
44+
}

0 commit comments

Comments
 (0)
0