8000 ref: Remove usage of `makeMain` in tests (#10681) · GingerAdonis/sentry-javascript@551aa86 · GitHub
[go: up one dir, main page]

Skip to content

Commit 551aa86

Browse files
authored
ref: Remove usage of makeMain in tests (getsentry#10681)
This removes most (but not all) usage of `makeMain` in our own tests. Some node tests remain for now, most of these will eventually be removed, so I figured no need to change them right now.
1 parent b420f19 commit 551aa86

File tree

15 files changed

+242
-276
lines changed

15 files changed

+242
-276
lines changed

packages/bun/test/integrations/bunserver.test.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeAll, beforeEach, describe, expect, test } from 'bun:test';
2-
import { Hub, getDynamicSamplingContextFromSpan, makeMain, spanIsSampled, spanToJSON } from '@sentry/core';
2+
import { getDynamicSamplingContextFromSpan, setCurrentClient, spanIsSampled, spanToJSON } from '@sentry/core';
33

44
import { BunClient } from '../../src/client';
55
import { instrumentBunServe } from '../../src/integrations/bunserver';
@@ -9,7 +9,6 @@ import { getDefaultBunClientOptions } from '../helpers';
99
const DEFAULT_PORT = 22114;
1010

1111
describe('Bun Serve Integration', () => {
12-
let hub: Hub;
1312
let client: BunClient;
1413

1514
beforeAll(() => {
@@ -19,10 +18,8 @@ describe('Bun Serve Integration', () => {
1918
beforeEach(() => {
2019
const options = getDefaultBunClientOptions({ tracesSampleRate: 1, debug: true });
2120
client = new BunClient(options);
22-
// eslint-disable-next-line deprecation/deprecation
23-
hub = new Hub(client);
24-
// eslint-disable-next-line deprecation/deprecation
25-
makeMain(hub);
21+
setCurrentClient(client);
22+
client.init();
2623
});
2724

2825
test('generates a transaction around a request', async () => {

packages/core/test/lib/integration.test.ts

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { Integration, Options } from '@sentry/types';
22
import { logger } from '@sentry/utils';
3+
import { getCurrentScope } from '../../src/currentScopes';
34

4-
import { Hub, makeMain } from '../../src/hub';
55
import {
66
addIntegration,
77
convertIntegrationFnToClass,
88
getIntegrationsToSetup,
99
installedIntegrations,
1010
setupIntegration,
1111
} from '../../src/integration';
12+
import { setCurrentClient } from '../../src/sdk';
1213
import { TestClient, getDefaultTestClientOptions } from '../mocks/client';
1314

1415
function getTestClient(): TestClient {
@@ -617,10 +618,7 @@ describe('addIntegration', () => {
617618
}
618619

619620
const client = getTestClient();
620-
// eslint-disable-next-line deprecation/deprecation
621-
const hub = new Hub(client);
622-
// eslint-disable-next-line deprecation/deprecation
623-
makeMain(hub);
621+
setCurrentClient(client);
624622

625623
const integration = new CustomIntegration();
626624
addIntegration(integration);
@@ -636,10 +634,7 @@ describe('addIntegration', () => {
636634
setupOnce = jest.fn();
637635
}
638636

639-
// eslint-disable-next-line deprecation/deprecation
640-
const hub = new Hub();
641-
// eslint-disable-next-line deprecation/deprecation
642-
makeMain(hub);
637+
getCurrentScope().setClient(undefined);
643638

644639
const integration = new CustomIntegration();
645640
addIntegration(integration);
@@ -662,10 +657,8 @@ describe('addIntegration', () => {
662657
}
663658

664659
const client = getTestClient();
665-
// eslint-disable-next-line deprecation/deprecation
666-
const hub = new Hub(client);
667-
// eslint-disable-next-line deprecation/deprecation
668-
makeMain(hub);
660+
setCurrentClient(client);
661+
client.init();
669662

670663
const integration = new CustomIntegration();
671664
addIntegration(integration);
@@ -686,10 +679,8 @@ describe('addIntegration', () => {
686679
}
687680

688681
const client = getTestClient();
689-
// eslint-disable-next-line deprecation/deprecation
690-
const hub = new Hub(client);
691-
// eslint-disable-next-line deprecation/deprecation
692-
makeMain(hub);
682+
setCurrentClient(client);
683+
client.init();
693684

694685
const integration1 = new CustomIntegration();
695686
const integration2 = new CustomIntegration();

packages/core/test/lib/scope.test.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { Attachment, Breadcrumb, Client, Event } from '@sentry/types';
22
import {
3-
Hub,
43
addTracingExtensions,
54
applyScopeDataToEvent,
65
getActiveSpan,
76
getCurrentScope,
87
getGlobalScope,
98
getIsolationScope,
10-
makeMain,
9+
setCurrentClient,
1110
setGlobalScope,
1211
spanToJSON,
1312
startInactiveSpan,
@@ -555,10 +554,8 @@ describe('withActiveSpan()', () => {
555554
beforeEach(() => {
556555
const options = getDefaultTestClientOptions({ enableTracing: true });
557556
const client = new TestClient(options);
558-
const scope = new Scope();
559-
// eslint-disable-next-line deprecation/deprecation
560-
const hub = new Hub(client, scope);
561-
makeMain(hub); // eslint-disable-line deprecation/deprecation
557+
setCurrentClient(client);
558+
client.init();
562559
});
563560

564561
it('should set the active span within the callback', () => {

packages/core/test/lib/sdk.test.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Hub, captureCheckIn, makeMain, setCurrentClient } from '@sentry/core';
1+
import { captureCheckIn, getCurrentScope, setCurrentClient } from '@sentry/core';
22
import type { Client, Integration, IntegrationFnResult } from '@sentry/types';
33

44
import { installedIntegrations } from '../../src/integration';
@@ -86,13 +86,6 @@ describe('SDK', () => {
8686
});
8787

8888
describe('captureCheckIn', () => {
89-
afterEach(function () {
90-
// eslint-disable-next-line deprecation/deprecation
91-
const hub = new Hub();
92-
// eslint-disable-next-line deprecation/deprecation
93-
makeMain(hub);
94-
});
95-
9689
it('returns an id when client is defined', () => {
9790
const client = {
9891
captureCheckIn: () => 'some-id-wasd-1234',
@@ -103,6 +96,7 @@ describe('captureCheckIn', () => {
10396
});
10497

10598
it('returns an id when client is undefined', () => {
99+
getCurrentScope().setClient(undefined);
106100
expect(captureCheckIn({ monitorSlug: 'gogogo', status: 'in_progress' })).toStrictEqual(expect.any(String));
107101
});
108102
});

packages/core/test/lib/tracing/dynamicSamplingContext.test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import type { TransactionSource } from '@sentry/types';
2-
import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, makeMain } from '../../../src';
2+
import {
3+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
4+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
5+
setCurrentClient,
6+
} from '../../../src';
37
import { Transaction, getDynamicSamplingContextFromSpan, startInactiveSpan } from '../../../src/tracing';
48
import { addTracingExtensions } from '../../../src/tracing';
59
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';
610

711
describe('getDynamicSamplingContextFromSpan', () => {
8-
let hub: Hub;
912
beforeEach(() => {
1013
const options = getDefaultTestClientOptions({ tracesSampleRate: 1.0, release: '1.0.1' });
1114
const client = new TestClient(options);
12-
// eslint-disable-next-line deprecation/deprecation
13-
hub = new Hub(client);
14-
// eslint-disable-next-line deprecation/deprecation
15-
makeMain(hub);
15+
setCurrentClient(client);
16+
client.init();
1617
addTracingExtensions();
1718
});
1819

packages/core/test/lib/tracing/errors.test.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BrowserClient } from '@sentry/browser';
2-
import { Hub, addTracingExtensions, makeMain, spanToJSON, startInactiveSpan, startSpan } from '@sentry/core';
2+
import { addTracingExtensions, setCurrentClient, spanToJSON, startInactiveSpan, startSpan } from '@sentry/core';
33
import type { HandlerDataError, HandlerDataUnhandledRejection } from '@sentry/types';
44

55
import { getDefaultBrowserClientOptions } from '../../../../tracing/test/testutils';
@@ -34,10 +34,9 @@ describe('registerErrorHandlers()', () => {
3434
mockAddGlobalErrorInstrumentationHandler.mockClear();
3535
mockAddGlobalUnhandledRejectionInstrumentationHandler.mockClear();
3636
const options = getDefaultBrowserClientOptions({ enableTracing: true });
37-
// eslint-disable-next-line deprecation/deprecation
38-
const hub = new Hub(new BrowserClient(options));
39-
// eslint-disable-next-line deprecation/deprecation
40-
makeMain(hub);
37+
const client = new BrowserClient(options);
38+
setCurrentClient(client);
39+
client.init();
4140
});
4241

4342
it('registers error instrumentation', () => {

0 commit comments

Comments
 (0)
0