Skip to content

Commit 29ed4da

Browse files
authored
fix(nuxt): Allow overwriting server-side defaultIntegrations (#18717)
There is no reason for spreading the user-provided options before adding the `defaultIntegrations`. This changes the order to allow overriding and allowing passing `defaultIntegrations: false`. Also added tests for that Came up in this review comment of another PR: #18671 (comment) Closes #18718 (added automatically)
1 parent a516745 commit 29ed4da

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

packages/nuxt/src/server/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import type { SentryNuxtServerOptions } from '../common/types';
2727
export function init(options: SentryNuxtServerOptions): Client | undefined {
2828
const sentryOptions = {
2929
environment: !isCjs() && import.meta.dev ? DEV_ENVIRONMENT : DEFAULT_ENVIRONMENT,
30-
...options,
3130
defaultIntegrations: getNuxtDefaultIntegrations(options),
31+
...options,
3232
};
3333

3434
applySdkMetadata(sentryOptions, 'nuxt', ['nuxt', 'node']);

packages/nuxt/test/client/sdk.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,41 @@ describe('Nuxt Client SDK', () => {
4141
it('returns client from init', () => {
4242
expect(init({})).not.toBeUndefined();
4343
});
44+
45+
it('uses default integrations when not provided in options', () => {
46+
init({ dsn: 'https://[email protected]/1337' });
47+
48+
expect(browserInit).toHaveBeenCalledTimes(1);
49+
const callArgs = browserInit.mock.calls[0]?.[0];
50+
expect(callArgs).toBeDefined();
51+
expect(callArgs?.defaultIntegrations).toBeDefined();
52+
expect(Array.isArray(callArgs?.defaultIntegrations)).toBe(true);
53+
});
54+
55+
it('allows options.defaultIntegrations to override default integrations', () => {
56+
const customIntegrations = [{ name: 'CustomIntegration' }];
57+
58+
init({
59+
dsn: 'https://[email protected]/1337',
60+
defaultIntegrations: customIntegrations as any,
61+
});
62+
63+
expect(browserInit).toHaveBeenCalledTimes(1);
64+
const callArgs = browserInit.mock.calls[0]?.[0];
65+
expect(callArgs).toBeDefined();
66+
expect(callArgs?.defaultIntegrations).toBe(customIntegrations);
67+
});
68+
69+
it('allows options.defaultIntegrations to be set to false', () => {
70+
init({
71+
dsn: 'https://[email protected]/1337',
72+
defaultIntegrations: false,
73+
});
74+
75+
expect(browserInit).toHaveBeenCalledTimes(1);
76+
const callArgs = browserInit.mock.calls[0]?.[0];
77+
expect(callArgs).toBeDefined();
78+
expect(callArgs?.defaultIntegrations).toBe(false);
79+
});
4480
});
4581
});

packages/nuxt/test/server/sdk.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,42 @@ describe('Nuxt Server SDK', () => {
4141
expect(init({})).not.toBeUndefined();
4242
});
4343

44+
it('uses default integrations when not provided in options', () => {
45+
init({ dsn: 'https://[email protected]/1337' });
46+
47+
expect(nodeInit).toHaveBeenCalledTimes(1);
48+
const callArgs = nodeInit.mock.calls[0]?.[0];
49+
expect(callArgs).toBeDefined();
50+
expect(callArgs?.defaultIntegrations).toBeDefined();
51+
expect(Array.isArray(callArgs?.defaultIntegrations)).toBe(true);
52+
});
53+
54+
it('allows options.defaultIntegrations to override default integrations', () => {
55+
const customIntegrations = [{ name: 'CustomIntegration' }];
56+
57+
init({
58+
dsn: 'https://[email protected]/1337',
59+
defaultIntegrations: customIntegrations as any,
60+
});
61+
62+
expect(nodeInit).toHaveBeenCalledTimes(1);
63+
const callArgs = nodeInit.mock.calls[0]?.[0];
64+
expect(callArgs).toBeDefined();
65+
expect(callArgs?.defaultIntegrations).toBe(customIntegrations);
66+
});
67+
68+
it('allows options.defaultIntegrations to be set to false', () => {
69+
init({
70+
dsn: 'https://[email protected]/1337',
71+
defaultIntegrations: false,
72+
});
73+
74+
expect(nodeInit).toHaveBeenCalledTimes(1);
75+
const callArgs = nodeInit.mock.calls[0]?.[0];
76+
expect(callArgs).toBeDefined();
77+
expect(callArgs?.defaultIntegrations).toBe(false);
78+
});
79+
4480
describe('lowQualityTransactionsFilter', () => {
4581
const options = { debug: false };
4682
const filter = lowQualityTransactionsFilter(options);

0 commit comments

Comments
 (0)