Skip to content

Commit 4b99338

Browse files
committed
add init unit tests
1 parent b1bf9e7 commit 4b99338

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { getSDKSource } from '@sentry/core';
2+
import type { NodeOptions } from '@sentry/node';
3+
import { initWithoutDefaultIntegrations } from '@sentry/node';
4+
import { describe, expect, test, vi } from 'vitest';
5+
import { init } from '../src/init';
6+
7+
vi.mock('@sentry/core', async importOriginal => ({
8+
...(await importOriginal()),
9+
getSDKSource: vi.fn(),
10+
}));
11+
12+
vi.mock('@sentry/node', async importOriginal => ({
13+
...(await importOriginal()),
14+
initWithoutDefaultIntegrations: vi.fn(),
15+
}));
16+
17+
const mockGetSDKSource = vi.mocked(getSDKSource);
18+
const mockInitWithoutDefaultIntegrations = vi.mocked(initWithoutDefaultIntegrations);
19+
20+
describe('init', () => {
21+
test('should preserve user-provided tunnel option when SDK source is aws-lambda-layer', () => {
22+
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
23+
const options: NodeOptions = {
24+
tunnel: 'https://custom-tunnel.example.com',
25+
};
26+
27+
init(options);
28+
29+
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
30+
expect.objectContaining({
31+
tunnel: 'https://custom-tunnel.example.com',
32+
}),
33+
);
34+
});
35+
36+
test('should set default tunnel when SDK source is aws-lambda-layer and no tunnel provided', () => {
37+
mockGetSDKSource.mockReturnValue('aws-lambda-layer');
38+
const options: NodeOptions = {};
39+
40+
init(options);
41+
42+
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
43+
expect.objectContaining({
44+
tunnel: 'http://localhost:9000/envelope',
45+
}),
46+
);
47+
});
48+
49+
test('should not set tunnel when SDK source is not aws-lambda-layer', () => {
50+
mockGetSDKSource.mockReturnValue('npm');
51+
const options: NodeOptions = {};
52+
53+
init(options);
54+
55+
expect(mockInitWithoutDefaultIntegrations).toHaveBeenCalledWith(
56+
expect.not.objectContaining({
57+
tunnel: expect.any(String),
58+
}),
59+
);
60+
});
61+
});

0 commit comments

Comments
 (0)