Skip to content

Commit 63073c0

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

File tree

16 files changed

+54
-51
lines changed

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([

0 commit comments

Comments
 (0)