Skip to content

Commit 4d7151b

Browse files
committed
update tests and keep next major
1 parent 556d1e3 commit 4d7151b

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

packages/nextjs/src/config/util.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ function resolveNextjsPackageJson(): string | undefined {
3333
* Checks if the current Next.js version supports the runAfterProductionCompile hook.
3434
* This hook was introduced in Next.js 15.4.1. (https://github.com/vercel/next.js/pull/77345)
3535
*
36+
* @param version - Optional version string to check. If not provided, will call getNextjsVersion()
3637
* @returns true if Next.js version is 15.4.1 or higher
3738
*/
38-
export function supportsProductionCompileHook(): boolean {
39-
const version = getNextjsVersion();
40-
if (!version) {
39+
export function supportsProductionCompileHook(version?: string): boolean {
40+
const versionToCheck = version ?? getNextjsVersion();
41+
if (!versionToCheck) {
4142
return false;
4243
}
4344

44-
const { major, minor, patch } = parseSemver(version);
45+
const { major, minor, patch } = parseSemver(versionToCheck);
4546

4647
if (major === undefined || minor === undefined || patch === undefined) {
4748
return false;

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,13 @@ function getFinalConfigObject(
253253
}
254254

255255
let nextMajor: number | undefined;
256+
if (nextJsVersion) {
257+
const { major } = parseSemver(nextJsVersion);
258+
nextMajor = major;
259+
}
260+
256261
const isTurbopack = process.env.TURBOPACK;
257-
const isTurbopackSupported = supportsProductionCompileHook();
262+
const isTurbopackSupported = supportsProductionCompileHook(nextJsVersion);
258263

259264
if (!isTurbopackSupported && isTurbopack) {
260265
if (process.env.NODE_ENV === 'development') {

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

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ describe('withSentryConfig', () => {
183183
expect(finalConfigWithoutTurbopack.webpack).toBe(originalWebpackFunction);
184184

185185
process.env.TURBOPACK = '1';
186-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
186+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
187187
const finalConfigWithTurbopack = materializeFinalNextConfig(configWithWebpack, undefined, sentryOptions);
188188
expect(finalConfigWithTurbopack.webpack).toBe(originalWebpackFunction);
189189
});
190190

191191
it('preserves original webpack config when Turbopack is enabled (ignores disableSentryWebpackConfig flag)', () => {
192192
process.env.TURBOPACK = '1';
193-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
193+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
194194

195195
const originalWebpackFunction = vi.fn();
196196
const configWithWebpack = {
@@ -216,7 +216,7 @@ describe('withSentryConfig', () => {
216216

217217
it('preserves original webpack config when Turbopack is enabled and disableSentryWebpackConfig is true', () => {
218218
process.env.TURBOPACK = '1';
219-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
219+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
220220

221221
const sentryOptions = {
222222
disableSentryWebpackConfig: true,
@@ -235,7 +235,7 @@ describe('withSentryConfig', () => {
235235

236236
it('preserves undefined webpack when Turbopack is enabled, disableSentryWebpackConfig is true, and no original webpack config exists', () => {
237237
process.env.TURBOPACK = '1';
238-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
238+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
239239

240240
const sentryOptions = {
241241
disableSentryWebpackConfig: true,
@@ -253,7 +253,7 @@ describe('withSentryConfig', () => {
253253

254254
it('includes turbopack config when Turbopack is supported and enabled', () => {
255255
process.env.TURBOPACK = '1';
256-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
256+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
257257

258258
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
259259

@@ -279,7 +279,7 @@ describe('withSentryConfig', () => {
279279

280280
it('enables productionBrowserSourceMaps for supported turbopack builds when sourcemaps are not disabled', () => {
281281
process.env.TURBOPACK = '1';
282-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
282+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
283283

284284
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
285285

@@ -288,7 +288,7 @@ describe('withSentryConfig', () => {
288288

289289
it('does not enable productionBrowserSourceMaps when sourcemaps are disabled', () => {
290290
process.env.TURBOPACK = '1';
291-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
291+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
292292

293293
const cleanConfig = { ...exportedNextConfig };
294294
delete cleanConfig.productionBrowserSourceMaps;
@@ -329,7 +329,7 @@ describe('withSentryConfig', () => {
329329

330330
it('preserves user-configured productionBrowserSourceMaps setting', () => {
331331
process.env.TURBOPACK = '1';
332-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
332+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
333333

334334
const configWithSourceMaps = {
335335
...exportedNextConfig,
@@ -343,7 +343,7 @@ describe('withSentryConfig', () => {
343343

344344
it('preserves user-configured productionBrowserSourceMaps: true setting', () => {
345345
process.env.TURBOPACK = '1';
346-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
346+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
347347

348348
const configWithSourceMaps = {
349349
...exportedNextConfig,
@@ -363,7 +363,7 @@ describe('withSentryConfig', () => {
363363

364364
it('automatically enables deleteSourcemapsAfterUpload for turbopack builds when not explicitly set', () => {
365365
process.env.TURBOPACK = '1';
366-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
366+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
367367

368368
// Use a clean config without productionBrowserSourceMaps to ensure it gets auto-enabled
369369
const cleanConfig = { ...exportedNextConfig };
@@ -382,7 +382,7 @@ describe('withSentryConfig', () => {
382382

383383
it('preserves explicitly configured deleteSourcemapsAfterUpload setting', () => {
384384
process.env.TURBOPACK = '1';
385-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
385+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
386386

387387
const sentryOptions = {
388388
sourcemaps: {
@@ -397,7 +397,7 @@ describe('withSentryConfig', () => {
397397

398398
it('does not modify deleteSourcemapsAfterUpload when sourcemaps are disabled', () => {
399399
process.env.TURBOPACK = '1';
400-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
400+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
401401

402402
const sentryOptions = {
403403
sourcemaps: {
@@ -412,7 +412,7 @@ describe('withSentryConfig', () => {
412412

413413
it('does not enable deleteSourcemapsAfterUpload when user pre-configured productionBrowserSourceMaps: true', () => {
414414
process.env.TURBOPACK = '1';
415-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
415+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
416416

417417
const configWithSourceMapsPreEnabled = {
418418
...exportedNextConfig,
@@ -431,7 +431,7 @@ describe('withSentryConfig', () => {
431431

432432
it('does not enable sourcemaps or deletion when user explicitly sets productionBrowserSourceMaps: false', () => {
433433
process.env.TURBOPACK = '1';
434-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
434+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
435435

436436
const configWithSourceMapsDisabled = {
437437
...exportedNextConfig,
@@ -451,7 +451,7 @@ describe('withSentryConfig', () => {
451451

452452
it('logs correct message when enabling sourcemaps for turbopack', () => {
453453
process.env.TURBOPACK = '1';
454-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
454+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
455455
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
456456

457457
const cleanConfig = { ...exportedNextConfig };
@@ -472,7 +472,7 @@ describe('withSentryConfig', () => {
472472

473473
it('warns about automatic sourcemap deletion for turbopack builds', () => {
474474
process.env.TURBOPACK = '1';
475-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
475+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
476476
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
477477

478478
// Use a clean config without productionBrowserSourceMaps to trigger automatic enablement
@@ -494,22 +494,25 @@ describe('withSentryConfig', () => {
494494
});
495495

496496
describe('version compatibility', () => {
497-
it('enables sourcemaps for Next.js 15.3.0', () => {
497+
it('enables sourcemaps for Next.js 15.4.1', () => {
498498
process.env.TURBOPACK = '1';
499-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
499+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
500500

501501
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
502502

503503
expect(finalConfig.productionBrowserSourceMaps).toBe(true);
504504
});
505505

506-
it('enables sourcemaps for Next.js 15.4.0', () => {
506+
it('does not enable sourcemaps for Next.js 15.4.0', () => {
507507
process.env.TURBOPACK = '1';
508508
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.0');
509509

510-
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
510+
const cleanConfig = { ...exportedNextConfig };
511+
delete cleanConfig.productionBrowserSourceMaps;
511512

512-
expect(finalConfig.productionBrowserSourceMaps).toBe(true);
513+
const finalConfig = materializeFinalNextConfig(cleanConfig);
514+
515+
expect(finalConfig.productionBrowserSourceMaps).toBeUndefined();
513516
});
514517

515518
it('enables sourcemaps for Next.js 16.0.0', () => {
@@ -535,7 +538,7 @@ describe('withSentryConfig', () => {
535538

536539
it('enables sourcemaps for supported canary versions', () => {
537540
process.env.TURBOPACK = '1';
538-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0-canary.28');
541+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1-canary.1');
539542

540543
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
541544

@@ -544,7 +547,7 @@ describe('withSentryConfig', () => {
544547

545548
it('does not enable sourcemaps for unsupported canary versions', () => {
546549
process.env.TURBOPACK = '1';
547-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0-canary.27');
550+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.0-canary.999');
548551

549552
const cleanConfig = { ...exportedNextConfig };
550553
delete cleanConfig.productionBrowserSourceMaps;
@@ -558,7 +561,7 @@ describe('withSentryConfig', () => {
558561
describe('edge cases', () => {
559562
it('handles undefined sourcemaps option', () => {
560563
process.env.TURBOPACK = '1';
561-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
564+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
562565

563566
const sentryOptions = {}; // no sourcemaps property
564567

@@ -569,7 +572,7 @@ describe('withSentryConfig', () => {
569572

570573
it('handles empty sourcemaps object', () => {
571574
process.env.TURBOPACK = '1';
572-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
575+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
573576

574577
// Use a clean config without productionBrowserSourceMaps to trigger automatic enablement
575578
const cleanConfig = { ...exportedNextConfig };
@@ -586,7 +589,7 @@ describe('withSentryConfig', () => {
586589

587590
it('works when TURBOPACK env var is truthy string', () => {
588591
process.env.TURBOPACK = 'true';
589-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
592+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
590593

591594
const finalConfig = materializeFinalNextConfig(exportedNextConfig);
592595

@@ -595,7 +598,7 @@ describe('withSentryConfig', () => {
595598

596599
it('does not enable sourcemaps when TURBOPACK env var is falsy', () => {
597600
process.env.TURBOPACK = '';
598-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
601+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
599602

600603
const cleanConfig = { ...exportedNextConfig };
601604
delete cleanConfig.productionBrowserSourceMaps;
@@ -607,7 +610,7 @@ describe('withSentryConfig', () => {
607610

608611
it('works correctly with tunnel route configuration', () => {
609612
process.env.TURBOPACK = '1';
610-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
613+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
611614

612615
// Use a clean config without productionBrowserSourceMaps to trigger automatic enablement
613616
const cleanConfig = { ...exportedNextConfig };
@@ -627,7 +630,7 @@ describe('withSentryConfig', () => {
627630

628631
it('works correctly with custom release configuration', () => {
629632
process.env.TURBOPACK = '1';
630-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
633+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
631634

632635
// Clear environment variable to test custom release name
633636
const originalSentryRelease = process.env.SENTRY_RELEASE;
@@ -658,7 +661,7 @@ describe('withSentryConfig', () => {
658661

659662
it('does not interfere with other Next.js configuration options', () => {
660663
process.env.TURBOPACK = '1';
661-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
664+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
662665

663666
const configWithOtherOptions = {
664667
...exportedNextConfig,
@@ -677,7 +680,7 @@ describe('withSentryConfig', () => {
677680

678681
it('works correctly when turbopack config already exists', () => {
679682
process.env.TURBOPACK = '1';
680-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
683+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
681684

682685
const configWithTurbopack = {
683686
...exportedNextConfig,
@@ -1069,7 +1072,7 @@ describe('withSentryConfig', () => {
10691072
delete process.env.TURBOPACK;
10701073
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
10711074
process.env.NODE_ENV = 'development';
1072-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1075+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
10731076
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
10741077
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
10751078

@@ -1122,7 +1125,7 @@ describe('withSentryConfig', () => {
11221125
process.env.TURBOPACK = '1';
11231126
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
11241127
process.env.NODE_ENV = 'test';
1125-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1128+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
11261129
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
11271130
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
11281131

@@ -1139,7 +1142,7 @@ describe('withSentryConfig', () => {
11391142
process.env.TURBOPACK = '';
11401143
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
11411144
process.env.NODE_ENV = 'development';
1142-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1145+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
11431146
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
11441147
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
11451148

@@ -1156,7 +1159,7 @@ describe('withSentryConfig', () => {
11561159
process.env.TURBOPACK = '0';
11571160
// @ts-expect-error - NODE_ENV is read-only in types but we need to set it for testing
11581161
process.env.NODE_ENV = 'development';
1159-
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.3.0');
1162+
vi.spyOn(util, 'getNextjsVersion').mockReturnValue('15.4.1');
11601163
vi.spyOn(util, 'supportsProductionCompileHook').mockReturnValue(false);
11611164
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
11621165

0 commit comments

Comments
 (0)