Skip to content

Commit 63073c0

Browse files
committed
Fix more tests
1 parent 18e769c commit 63073c0

16 files changed

+54
-51
lines changed

packages/node/test/integration/breadcrumbs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { cleanupOtel, mockSdkInit } from '../helpers/mockSdkInit';
99
describe('Integration | breadcrumbs', () => {
1010
const beforeSendTransaction = vi.fn(() => null);
1111

12-
afterEach(() => {
13-
cleanupOtel();
12+
afterEach(async () => {
13+
await cleanupOtel();
1414
});
1515

1616
describe('without tracing', () => {

packages/node/test/integration/scope.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import type { NodeClient } from '../../src/sdk/client';
88
import { cleanupOtel, mockSdkInit, resetGlobals } from '../helpers/mockSdkInit';
99

1010
describe('Integration | Scope', () => {
11-
afterEach(() => {
12-
cleanupOtel();
11+
afterEach(async () => {
12+
await cleanupOtel();
1313
});
1414

1515
describe.each([

packages/node/test/integration/transactions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import * as Sentry from '../../src';
1010
import { cleanupOtel, getProvider, mockSdkInit } from '../helpers/mockSdkInit';
1111

1212
describe('Integration | Transactions', () => {
13-
afterEach(() => {
13+
afterEach(async () => {
1414
vi.restoreAllMocks();
15-
cleanupOtel();
15+
await cleanupOtel();
1616
});
1717

1818
it('correctly creates transaction & spans', async () => {

packages/node/test/sdk/api.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
33
import { getActiveSpan, getClient, startInactiveSpan, startSpan, withActiveSpan } from '../../src';
44
import { cleanupOtel, mockSdkInit } from '../helpers/mockSdkInit';
55

6-
afterEach(() => {
6+
afterEach(async () => {
77
vi.restoreAllMocks();
8-
cleanupOtel();
8+
await cleanupOtel();
99
});
1010

1111
describe('withActiveSpan()', () => {

packages/node/test/sdk/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ describe('NodeClient', () => {
1818
setOpenTelemetryContextAsyncContextStrategy();
1919
});
2020

21-
afterEach(() => {
21+
afterEach(async () => {
2222
vi.restoreAllMocks();
23-
cleanupOtel();
23+
await cleanupOtel();
2424
});
2525

2626
it('sets correct metadata', () => {

packages/node/test/sdk/init.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('init()', () => {
3131
mockAutoPerformanceIntegrations = vi.spyOn(auto, 'getAutoPerformanceIntegrations').mockImplementation(() => []);
3232
});
3333

34-
afterEach(() => {
35-
cleanupOtel();
34+
afterEach(async () => {
35+
await cleanupOtel();
3636

3737
vi.clearAllMocks();
3838
});
@@ -152,9 +152,9 @@ describe('init()', () => {
152152
});
153153

154154
describe('validateOpenTelemetrySetup', () => {
155-
afterEach(() => {
155+
afterEach(async () => {
156156
global.__SENTRY__ = {};
157-
cleanupOtel();
157+
await cleanupOtel();
158158
vi.clearAllMocks();
159159
});
160160

packages/node/test/utils/ensureIsWrapped.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const wrappedfunction = Object.assign(() => {}, {
1212
});
1313

1414
describe('ensureIsWrapped', () => {
15-
afterEach(() => {
15+
afterEach(async () => {
1616
vi.restoreAllMocks();
17-
cleanupOtel();
17+
await cleanupOtel();
1818
resetGlobals();
1919
});
2020

packages/opentelemetry/test/helpers/mockSdkInit.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { ProxyTracerProvider, context, propagation, trace } from '@opentelemetry/api';
22
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
3-
import type { ClientOptions, Options } from '@sentry/core';
3+
import type { ClientOptions, Options} from '@sentry/core';
4+
import { getClient } from '@sentry/core';
45

5-
import { getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/core';
6+
import { getCurrentScope, getGlobalScope, getIsolationScope, flush } from '@sentry/core';
67
import { setOpenTelemetryContextAsyncContextStrategy } from '../../src/asyncContextStrategy';
78
import { clearOpenTelemetrySetupCheck } from '../../src/utils/setupCheck';
89
import { init as initTestClient } from './TestClient';
910
import { initOtel } from './initOtel';
11+
import type { OpenTelemetryClient } from '../../src/types';
1012

1113
const PUBLIC_DSN = 'https://username@domain/123';
1214

@@ -33,25 +35,26 @@ export function mockSdkInit(options?: Partial<ClientOptions>) {
3335
init({ dsn: PUBLIC_DSN, ...options });
3436
}
3537

36-
export function cleanupOtel(_provider?: BasicTracerProvider): void {
38+
export async function cleanupOtel(_provider?: BasicTracerProvider): Promise<void> {
3739
clearOpenTelemetrySetupCheck();
40+
3841
const provider = getProvider(_provider);
3942

40-
if (!provider) {
41-
return;
43+
if (provider) {
44+
await provider.forceFlush();
45+
await provider.shutdown();
4246
}
4347

44-
void provider.forceFlush();
45-
void provider.shutdown();
46-
4748
// Disable all globally registered APIs
4849
trace.disable();
4950
context.disable();
5051
propagation.disable();
52+
53+
await flush();
5154
}
5255

5356
export function getProvider(_provider?: BasicTracerProvider): BasicTracerProvider | undefined {
54-
let provider = _provider || trace.getTracerProvider();
57+
let provider = _provider || getClient<OpenTelemetryClient>()?.traceProvider || trace.getTracerProvider();
5558

5659
if (provider instanceof ProxyTracerProvider) {
5760
provider = provider.getDelegate();

packages/opentelemetry/test/integration/breadcrumbs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { cleanupOtel, mockSdkInit } from '../helpers/mockSdkInit';
88
describe('Integration | breadcrumbs', () => {
99
const beforeSendTransaction = vi.fn(() => null);
1010

11-
afterEach(() => {
12-
cleanupOtel();
11+
afterEach(async () => {
12+
await cleanupOtel();
1313
});
1414

1515
describe('without tracing', () => {

packages/opentelemetry/test/integration/scope.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import type { TestClientInterface } from '../helpers/TestClient';
1515
import { cleanupOtel, mockSdkInit } from '../helpers/mockSdkInit';
1616

1717
describe('Integration | Scope', () => {
18-
afterEach(() => {
19-
cleanupOtel();
18+
afterEach(async () => {
19+
await cleanupOtel();
2020
});
2121

2222
describe.each([

packages/opentelemetry/test/integration/transactions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import type { TestClientInterface } from '../helpers/TestClient';
2424
import { cleanupOtel, getProvider, mockSdkInit } from '../helpers/mockSdkInit';
2525

2626
describe('Integration | Transactions', () => {
27-
afterEach(() => {
27+
afterEach(async () => {
2828
vi.restoreAllMocks();
2929
vi.useRealTimers();
30-
cleanupOtel();
30+
await cleanupOtel();
3131
});
3232

3333
it('correctly creates transaction & spans', async () => {

packages/opentelemetry/test/propagator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('SentryPropagator', () => {
3131
});
3232
});
3333

34-
afterEach(() => {
35-
cleanupOtel();
34+
afterEach(async () => {
35+
await cleanupOtel();
3636
});
3737

3838
it('returns fields set', () => {

packages/opentelemetry/test/sampler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { TestClient, getDefaultTestClientOptions } from './helpers/TestClient';
1111
import { cleanupOtel } from './helpers/mockSdkInit';
1212

1313
describe('SentrySampler', () => {
14-
afterEach(() => {
15-
cleanupOtel();
14+
afterEach(async () => {
15+
await cleanupOtel();
1616
});
1717

1818
it('works with tracesSampleRate=0', () => {

packages/opentelemetry/test/spanExporter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ describe('createTransactionForOtelSpan', () => {
1212
});
1313
});
1414

15-
afterEach(() => {
16-
cleanupOtel();
15+
afterEach(async () => {
16+
await cleanupOtel();
1717
});
1818

1919
it('works with a basic span', () => {

packages/opentelemetry/test/trace.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('trace', () => {
3838
mockSdkInit({ tracesSampleRate: 1 });
3939
});
4040

41-
afterEach(() => {
42-
cleanupOtel();
41+
afterEach(async () => {
42+
await cleanupOtel();
4343
});
4444

4545
describe('startSpan', () => {
@@ -1352,8 +1352,8 @@ describe('trace (tracing disabled)', () => {
13521352
mockSdkInit({ tracesSampleRate: 0 });
13531353
});
13541354

1355-
afterEach(() => {
1356-
cleanupOtel();
1355+
afterEach(async () => {
1356+
await cleanupOtel();
13571357
});
13581358

13591359
it('startSpan calls callback without span', () => {
@@ -1376,8 +1376,8 @@ describe('trace (tracing disabled)', () => {
13761376
});
13771377

13781378
describe('trace (sampling)', () => {
1379-
afterEach(() => {
1380-
cleanupOtel();
1379+
afterEach(async () => {
1380+
await cleanupOtel();
13811381
vi.clearAllMocks();
13821382
});
13831383

@@ -1707,8 +1707,8 @@ describe('HTTP methods (sampling)', () => {
17071707
mockSdkInit({ tracesSampleRate: 1 });
17081708
});
17091709

1710-
afterEach(() => {
1711-
cleanupOtel();
1710+
afterEach(async () => {
1711+
await cleanupOtel();
17121712
});
17131713

17141714
it('does sample when HTTP method is other than OPTIONS or HEAD', () => {
@@ -1762,8 +1762,8 @@ describe('continueTrace', () => {
17621762
mockSdkInit({ tracesSampleRate: 1 });
17631763
});
17641764

1765-
afterEach(() => {
1766-
cleanupOtel();
1765+
afterEach(async () => {
1766+
await cleanupOtel();
17671767
});
17681768

17691769
it('works without trace & baggage data', () => {
@@ -1864,8 +1864,8 @@ describe('suppressTracing', () => {
18641864
mockSdkInit({ tracesSampleRate: 1 });
18651865
});
18661866

1867-
afterEach(() => {
1868-
cleanupOtel();
1867+
afterEach(async () => {
1868+
await cleanupOtel();
18691869
});
18701870

18711871
it('works for a root span', () => {

packages/opentelemetry/test/utils/getTraceData.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ describe('getTraceData', () => {
1212
mockSdkInit();
1313
});
1414

15-
afterEach(() => {
16-
cleanupOtel();
15+
afterEach(async () => {
16+
await cleanupOtel();
1717
vi.clearAllMocks();
1818
});
1919

0 commit comments

Comments
 (0)