Skip to content

Commit 9ef882c

Browse files
committed
tests: update Sentry options structure to use webpack namespace and add deprecation warnings for top-level options
1 parent 444c778 commit 9ef882c

File tree

2 files changed

+123
-18
lines changed

2 files changed

+123
-18
lines changed

packages/nextjs/test/config/getBuildPluginOptions.test.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ describe('getBuildPluginOptions', () => {
129129
const result = getBuildPluginOptions({
130130
sentryBuildOptions: {
131131
...baseSentryOptions,
132-
widenClientFileUpload: true,
132+
webpack: {
133+
widenClientFileUpload: true,
134+
},
133135
},
134136
releaseName: mockReleaseName,
135137
distDirAbsPath: mockDistDirAbsPath,
@@ -573,13 +575,15 @@ describe('getBuildPluginOptions', () => {
573575
create: true,
574576
vcsRemote: 'origin',
575577
},
576-
unstable_sentryWebpackPluginOptions: {
577-
release: {
578-
setCommits: {
579-
auto: true,
580-
},
581-
deploy: {
582-
env: 'production',
578+
webpack: {
579+
unstable_sentryWebpackPluginOptions: {
580+
release: {
581+
setCommits: {
582+
auto: true,
583+
},
584+
deploy: {
585+
env: 'production',
586+
},
583587
},
584588
},
585589
},
@@ -592,7 +596,7 @@ describe('getBuildPluginOptions', () => {
592596
buildTool: 'webpack-client',
593597
});
594598

595-
// The unstable_sentryWebpackPluginOptions.release is spread at the end and may override base properties
599+
// The webpack.unstable_sentryWebpackPluginOptions.release is spread at the end and may override base properties
596600
expect(result.release).toHaveProperty('setCommits.auto', true);
597601
expect(result.release).toHaveProperty('deploy.env', 'production');
598602
});
@@ -603,12 +607,14 @@ describe('getBuildPluginOptions', () => {
603607
const sentryBuildOptions: SentryBuildOptions = {
604608
org: 'test-org',
605609
project: 'test-project',
606-
reactComponentAnnotation: {
607-
enabled: true,
608-
},
609-
unstable_sentryWebpackPluginOptions: {
610+
webpack: {
610611
reactComponentAnnotation: {
611-
enabled: false, // This will override the base setting
612+
enabled: true,
613+
},
614+
unstable_sentryWebpackPluginOptions: {
615+
reactComponentAnnotation: {
616+
enabled: false, // This will override the base setting
617+
},
612618
},
613619
},
614620
};
@@ -695,10 +701,12 @@ describe('getBuildPluginOptions', () => {
695701
const sentryBuildOptions: SentryBuildOptions = {
696702
org: 'test-org',
697703
project: 'test-project',
698-
unstable_sentryWebpackPluginOptions: {
699-
applicationKey: 'test-app-key',
700-
sourcemaps: {
701-
disable: false,
704+
webpack: {
705+
unstable_sentryWebpackPluginOptions: {
706+
applicationKey: 'test-app-key',
707+
sourcemaps: {
708+
disable: false,
709+
},
702710
},
703711
},
704712
};

packages/nextjs/test/config/withSentryConfig.test.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,103 @@ describe('withSentryConfig', () => {
359359
expect(finalConfigOld.webpack).toBeInstanceOf(Function);
360360
});
361361
});
362+
363+
describe('deprecation warnings', () => {
364+
let consoleWarnSpy: ReturnType<typeof vi.spyOn>;
365+
366+
beforeEach(() => {
367+
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
368+
});
369+
370+
afterEach(() => {
371+
consoleWarnSpy.mockRestore();
372+
delete process.env.TURBOPACK;
373+
vi.restoreAllMocks();
374+
});
375+
376+
it('warns when using deprecated top-level options', () => {
377+
delete process.env.TURBOPACK;
378+
379+
const sentryOptions = {
380+
disableLogger: true,
381+
widenClientFileUpload: true,
382+
};
383+
384+
materializeFinalNextConfig(exportedNextConfig, undefined, sentryOptions);
385+
386+
expect(consoleWarnSpy).toHaveBeenCalledWith(
387+
expect.stringContaining('[@sentry/nextjs] DEPRECATION WARNING: disableLogger is deprecated'),
388+
);
389+
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining('Use webpack.treeshake.debugLogs instead'));
390+
expect(consoleWarnSpy).toHaveBeenCalledWith(
391+
expect.stringContaining('[@sentry/nextjs] DEPRECATION WARNING: widenClientFileUpload is deprecated'),
392+
);
393+
expect(consoleWarnSpy).toHaveBeenCalledWith(
394+
expect.stringContaining('Use webpack.widenClientFileUpload instead'),
395+
);
396+
});
397+
398+
it('does not warn when using new webpack path', () => {
399+
delete process.env.TURBOPACK;
400+
401+
const sentryOptions = {
402+
webpack: {
403+
treeshake: {
404+
debugLogs: true,
405+
},
406+
widenClientFileUpload: true,
407+
},
408+
};
409+
410+
materializeFinalNextConfig(exportedNextConfig, undefined, sentryOptions);
411+
412+
expect(consoleWarnSpy).not.toHaveBeenCalled();
413+
});
414+
415+
it('warns even when new path is also set', () => {
416+
delete process.env.TURBOPACK;
417+
418+
const sentryOptions = {
419+
disableLogger: true, // deprecated
420+
webpack: {
421+
treeshake: {
422+
debugLogs: false, // new path takes precedence
423+
},
424+
},
425+
};
426+
427+
materializeFinalNextConfig(exportedNextConfig, undefined, sentryOptions);
428+
429+
// Should warn because deprecated value is present
430+
expect(consoleWarnSpy).toHaveBeenCalledWith(
431+
expect.stringContaining('[@sentry/nextjs] DEPRECATION WARNING: disableLogger is deprecated'),
432+
);
433+
});
434+
435+
it('warns for multiple deprecated options at once', () => {
436+
delete process.env.TURBOPACK;
437+
438+
const sentryOptions = {
439+
disableLogger: true,
440+
automaticVercelMonitors: false,
441+
excludeServerRoutes: ['/api/test'],
442+
};
443+
444+
materializeFinalNextConfig(exportedNextConfig, undefined, sentryOptions);
445+
446+
// Should warn for all three deprecated options
447+
expect(consoleWarnSpy).toHaveBeenCalledWith(
448+
expect.stringContaining('[@sentry/nextjs] DEPRECATION WARNING: disableLogger is deprecated'),
449+
);
450+
expect(consoleWarnSpy).toHaveBeenCalledWith(
451+
expect.stringContaining('[@sentry/nextjs] DEPRECATION WARNING: automaticVercelMonitors is deprecated'),
452+
);
453+
expect(consoleWarnSpy).toHaveBeenCalledWith(
454+
expect.stringContaining('[@sentry/nextjs] DEPRECATION WARNING: excludeServerRoutes is deprecated'),
455+
);
456+
expect(consoleWarnSpy).toHaveBeenCalledTimes(3);
457+
});
458+
});
362459
});
363460

364461
describe('bundler detection', () => {

0 commit comments

Comments
 (0)