22import '../mocks' ;
33import * as core from '@sentry/core' ;
44import { describe , expect , it , vi } from 'vitest' ;
5+ import * as util from '../../../src/config/util' ;
56import * as getWebpackPluginOptionsModule from '../../../src/config/webpackPluginOptions' ;
67import {
78 CLIENT_SDK_CONFIG_FILE ,
@@ -188,8 +189,11 @@ describe('constructWebpackConfigFunction()', () => {
188189 } ) ;
189190
190191 describe ( 'edge runtime polyfills' , ( ) => {
191- it ( 'adds polyfills only for edge runtime in dev mode' , async ( ) => {
192- // Test edge runtime in dev mode - should add polyfills
192+ it ( 'adds polyfills only for edge runtime in dev mode on Next.js 13' , async ( ) => {
193+ // Mock Next.js version 13 - polyfills should be added
194+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '13.0.0' ) ;
195+
196+ // Test edge runtime in dev mode with Next.js 13 - should add polyfills
193197 const edgeDevBuildContext = { ...edgeBuildContext , dev : true } ;
194198 const edgeDevConfig = await materializeFinalWebpackConfig ( {
195199 exportedNextConfig,
@@ -201,6 +205,13 @@ describe('constructWebpackConfigFunction()', () => {
201205 expect ( edgeProvidePlugin ) . toBeDefined ( ) ;
202206 expect ( edgeDevConfig . resolve ?. alias ?. perf_hooks ) . toMatch ( / p e r f _ h o o k s \. j s $ / ) ;
203207
208+ vi . restoreAllMocks ( ) ;
209+ } ) ;
210+
211+ it ( 'does NOT add polyfills for edge runtime in prod mode even on Next.js 13' , async ( ) => {
212+ // Mock Next.js version 13 - but prod mode should still not add polyfills
213+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '13.0.0' ) ;
214+
204215 // Test edge runtime in prod mode - should NOT add polyfills
205216 const edgeProdBuildContext = { ...edgeBuildContext , dev : false } ;
206217 const edgeProdConfig = await materializeFinalWebpackConfig ( {
@@ -212,6 +223,13 @@ describe('constructWebpackConfigFunction()', () => {
212223 const edgeProdProvidePlugin = edgeProdConfig . plugins ?. find ( plugin => plugin . constructor . name === 'ProvidePlugin' ) ;
213224 expect ( edgeProdProvidePlugin ) . toBeUndefined ( ) ;
214225
226+ vi . restoreAllMocks ( ) ;
227+ } ) ;
228+
229+ it ( 'does NOT add polyfills for server runtime even on Next.js 13' , async ( ) => {
230+ // Mock Next.js version 13
231+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '13.0.0' ) ;
232+
215233 // Test server runtime in dev mode - should NOT add polyfills
216234 const serverDevBuildContext = { ...serverBuildContext , dev : true } ;
217235 const serverDevConfig = await materializeFinalWebpackConfig ( {
@@ -223,6 +241,13 @@ describe('constructWebpackConfigFunction()', () => {
223241 const serverProvidePlugin = serverDevConfig . plugins ?. find ( plugin => plugin . constructor . name === 'ProvidePlugin' ) ;
224242 expect ( serverProvidePlugin ) . toBeUndefined ( ) ;
225243
244+ vi . restoreAllMocks ( ) ;
245+ } ) ;
246+
247+ it ( 'does NOT add polyfills for client runtime even on Next.js 13' , async ( ) => {
248+ // Mock Next.js version 13
249+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '13.0.0' ) ;
250+
226251 // Test client runtime in dev mode - should NOT add polyfills
227252 const clientDevBuildContext = { ...clientBuildContext , dev : true } ;
228253 const clientDevConfig = await materializeFinalWebpackConfig ( {
@@ -233,6 +258,52 @@ describe('constructWebpackConfigFunction()', () => {
233258
234259 const clientProvidePlugin = clientDevConfig . plugins ?. find ( plugin => plugin . constructor . name === 'ProvidePlugin' ) ;
235260 expect ( clientProvidePlugin ) . toBeUndefined ( ) ;
261+
262+ vi . restoreAllMocks ( ) ;
263+ } ) ;
264+
265+ it ( 'does NOT add polyfills for edge runtime in dev mode on Next.js versions other than 13' , async ( ) => {
266+ const edgeDevBuildContext = { ...edgeBuildContext , dev : true } ;
267+
268+ // Test with Next.js 12 - should NOT add polyfills
269+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '12.3.0' ) ;
270+ const edgeConfigV12 = await materializeFinalWebpackConfig ( {
271+ exportedNextConfig,
272+ incomingWebpackConfig : serverWebpackConfig ,
273+ incomingWebpackBuildContext : edgeDevBuildContext ,
274+ } ) ;
275+ expect ( edgeConfigV12 . plugins ?. find ( plugin => plugin . constructor . name === 'ProvidePlugin' ) ) . toBeUndefined ( ) ;
276+ vi . restoreAllMocks ( ) ;
277+
278+ // Test with Next.js 14 - should NOT add polyfills
279+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '14.0.0' ) ;
280+ const edgeConfigV14 = await materializeFinalWebpackConfig ( {
281+ exportedNextConfig,
282+ incomingWebpackConfig : serverWebpackConfig ,
283+ incomingWebpackBuildContext : edgeDevBuildContext ,
284+ } ) ;
285+ expect ( edgeConfigV14 . plugins ?. find ( plugin => plugin . constructor . name === 'ProvidePlugin' ) ) . toBeUndefined ( ) ;
286+ vi . restoreAllMocks ( ) ;
287+
288+ // Test with Next.js 15 - should NOT add polyfills
289+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.0.0' ) ;
290+ const edgeConfigV15 = await materializeFinalWebpackConfig ( {
291+ exportedNextConfig,
292+ incomingWebpackConfig : serverWebpackConfig ,
293+ incomingWebpackBuildContext : edgeDevBuildContext ,
294+ } ) ;
295+ expect ( edgeConfigV15 . plugins ?. find ( plugin => plugin . constructor . name === 'ProvidePlugin' ) ) . toBeUndefined ( ) ;
296+ vi . restoreAllMocks ( ) ;
297+
298+ // Test with undefined Next.js version - should NOT add polyfills
299+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( undefined ) ;
300+ const edgeConfigUndefined = await materializeFinalWebpackConfig ( {
301+ exportedNextConfig,
302+ incomingWebpackConfig : serverWebpackConfig ,
303+ incomingWebpackBuildContext : edgeDevBuildContext ,
304+ } ) ;
305+ expect ( edgeConfigUndefined . plugins ?. find ( plugin => plugin . constructor . name === 'ProvidePlugin' ) ) . toBeUndefined ( ) ;
306+ vi . restoreAllMocks ( ) ;
236307 } ) ;
237308 } ) ;
238309} ) ;
0 commit comments