1
- import { describe , expect , it , vi } from 'vitest' ;
1
+ import { afterEach , describe , expect , it , vi } from 'vitest' ;
2
+ import * as util from '../../src/config/util' ;
3
+ import { DEFAULT_SERVER_EXTERNAL_PACKAGES } from '../../src/config/withSentryConfig' ;
2
4
import { defaultRuntimePhase , defaultsObject , exportedNextConfig , userNextConfig } from './fixtures' ;
3
5
import { materializeFinalNextConfig } from './testUtils' ;
4
6
@@ -22,10 +24,16 @@ describe('withSentryConfig', () => {
22
24
it ( "works when user's overall config is an object" , ( ) => {
23
25
const finalConfig = materializeFinalNextConfig ( exportedNextConfig ) ;
24
26
25
- expect ( finalConfig ) . toEqual (
27
+ const { webpack, experimental, ...restOfFinalConfig } = finalConfig ;
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ const { webpack : _userWebpack , experimental : _userExperimental , ...restOfUserConfig } = userNextConfig ;
30
+
31
+ expect ( restOfFinalConfig ) . toEqual ( restOfUserConfig ) ;
32
+ expect ( webpack ) . toBeInstanceOf ( Function ) ;
33
+ expect ( experimental ) . toEqual (
26
34
expect . objectContaining ( {
27
- ... userNextConfig ,
28
- webpack : expect . any ( Function ) , // `webpack` is tested specifically elsewhere
35
+ instrumentationHook : true ,
36
+ serverComponentsExternalPackages : expect . arrayContaining ( DEFAULT_SERVER_EXTERNAL_PACKAGES ) ,
29
37
} ) ,
30
38
) ;
31
39
} ) ;
@@ -35,10 +43,21 @@ describe('withSentryConfig', () => {
35
43
36
44
const finalConfig = materializeFinalNextConfig ( exportedNextConfigFunction ) ;
37
45
38
- expect ( finalConfig ) . toEqual (
46
+ const { webpack, experimental, ...restOfFinalConfig } = finalConfig ;
47
+ const {
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
+ webpack : _userWebpack ,
50
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
+ experimental : _userExperimental ,
52
+ ...restOfUserConfig
53
+ } = exportedNextConfigFunction ( ) ;
54
+
55
+ expect ( restOfFinalConfig ) . toEqual ( restOfUserConfig ) ;
56
+ expect ( webpack ) . toBeInstanceOf ( Function ) ;
57
+ expect ( experimental ) . toEqual (
39
58
expect . objectContaining ( {
40
- ... exportedNextConfigFunction ( ) ,
41
- webpack : expect . any ( Function ) , // `webpack` is tested specifically elsewhere
59
+ instrumentationHook : true ,
60
+ serverComponentsExternalPackages : expect . arrayContaining ( DEFAULT_SERVER_EXTERNAL_PACKAGES ) ,
42
61
} ) ,
43
62
) ;
44
63
} ) ;
@@ -75,4 +94,54 @@ describe('withSentryConfig', () => {
75
94
consoleWarnSpy . mockRestore ( ) ;
76
95
}
77
96
} ) ;
97
+
98
+ describe ( 'server packages configuration' , ( ) => {
99
+ afterEach ( ( ) => {
100
+ vi . restoreAllMocks ( ) ;
101
+ } ) ;
102
+
103
+ it ( 'uses serverExternalPackages for Next.js 15+' , ( ) => {
104
+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.0.0' ) ;
105
+ const finalConfig = materializeFinalNextConfig ( exportedNextConfig ) ;
106
+
107
+ expect ( finalConfig . serverExternalPackages ) . toBeDefined ( ) ;
108
+ expect ( finalConfig . serverExternalPackages ) . toEqual ( expect . arrayContaining ( DEFAULT_SERVER_EXTERNAL_PACKAGES ) ) ;
109
+ expect ( finalConfig . experimental ?. serverComponentsExternalPackages ) . toBeUndefined ( ) ;
110
+ } ) ;
111
+
112
+ it ( 'uses experimental.serverComponentsExternalPackages for Next.js < 15' , ( ) => {
113
+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '14.0.0' ) ;
114
+ const finalConfig = materializeFinalNextConfig ( exportedNextConfig ) ;
115
+
116
+ expect ( finalConfig . serverExternalPackages ) . toBeUndefined ( ) ;
117
+ expect ( finalConfig . experimental ?. serverComponentsExternalPackages ) . toBeDefined ( ) ;
118
+ expect ( finalConfig . experimental ?. serverComponentsExternalPackages ) . toEqual (
119
+ expect . arrayContaining ( DEFAULT_SERVER_EXTERNAL_PACKAGES ) ,
120
+ ) ;
121
+ } ) ;
122
+
123
+ it ( 'preserves existing packages in both versions' , ( ) => {
124
+ const existingPackages = [ '@some/existing-package' ] ;
125
+
126
+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '15.0.0' ) ;
127
+ const config15 = materializeFinalNextConfig ( {
128
+ ...exportedNextConfig ,
129
+ serverExternalPackages : existingPackages ,
130
+ } ) ;
131
+ expect ( config15 . serverExternalPackages ) . toEqual (
132
+ expect . arrayContaining ( [ ...existingPackages , ...DEFAULT_SERVER_EXTERNAL_PACKAGES ] ) ,
133
+ ) ;
134
+
135
+ vi . spyOn ( util , 'getNextjsVersion' ) . mockReturnValue ( '14.0.0' ) ;
136
+ const config14 = materializeFinalNextConfig ( {
137
+ ...exportedNextConfig ,
138
+ experimental : {
139
+ serverComponentsExternalPackages : existingPackages ,
140
+ } ,
141
+ } ) ;
142
+ expect ( config14 . experimental ?. serverComponentsExternalPackages ) . toEqual (
143
+ expect . arrayContaining ( [ ...existingPackages , ...DEFAULT_SERVER_EXTERNAL_PACKAGES ] ) ,
144
+ ) ;
145
+ } ) ;
146
+ } ) ;
78
147
} ) ;
0 commit comments