5
5
constructTurbopackConfig ,
6
6
safelyAddTurbopackRule ,
7
7
} from '../../../src/config/turbopack/constructTurbopackConfig' ;
8
- import type { NextConfigObject , SentryBuildOptions } from '../../../src/config/types' ;
8
+ import type { NextConfigObject } from '../../../src/config/types' ;
9
9
10
10
// Mock path.resolve to return a predictable loader path
11
11
vi . mock ( 'path' , async ( ) => {
@@ -18,25 +18,19 @@ vi.mock('path', async () => {
18
18
19
19
describe ( 'constructTurbopackConfig' , ( ) => {
20
20
const mockRouteManifest : RouteManifest = {
21
- routes : [
21
+ dynamicRoutes : [ { path : '/users/[id]' , regex : '/users/([^/]+)' , paramNames : [ 'id' ] } ] ,
22
+ staticRoutes : [
22
23
{ path : '/users' , regex : '/users' } ,
23
- { path : '/users/[id]' , regex : '/users/([^/]+)' , paramNames : [ 'id' ] } ,
24
24
{ path : '/api/health' , regex : '/api/health' } ,
25
25
] ,
26
26
} ;
27
27
28
- const mockSentryOptions : SentryBuildOptions = {
29
- org : 'test-org' ,
30
- project : 'test-project' ,
31
- } ;
32
-
33
28
describe ( 'without existing turbopack config' , ( ) => {
34
29
it ( 'should create a basic turbopack config when no manifest is provided' , ( ) => {
35
30
const userNextConfig : NextConfigObject = { } ;
36
31
37
32
const result = constructTurbopackConfig ( {
38
33
userNextConfig,
39
- userSentryOptions : mockSentryOptions ,
40
34
} ) ;
41
35
42
36
expect ( result ) . toEqual ( { } ) ;
@@ -47,7 +41,6 @@ describe('constructTurbopackConfig', () => {
47
41
48
42
const result = constructTurbopackConfig ( {
49
43
userNextConfig,
50
- userSentryOptions : mockSentryOptions ,
51
44
routeManifest : mockRouteManifest ,
52
45
} ) ;
53
46
@@ -75,11 +68,45 @@ describe('constructTurbopackConfig', () => {
75
68
76
69
constructTurbopackConfig ( {
77
70
userNextConfig,
78
- userSentryOptions : mockSentryOptions ,
79
71
routeManifest : mockRouteManifest ,
80
72
} ) ;
81
73
82
- expect ( pathResolveSpy ) . toHaveBeenCalledWith ( expect . any ( String ) , '../loaders/valueInjectionLoader.js' ) ;
74
+ expect ( pathResolveSpy ) . toHaveBeenCalledWith ( expect . any ( String ) , '..' , 'loaders' , 'valueInjectionLoader.js' ) ;
75
+ } ) ;
76
+
77
+ it ( 'should handle Windows-style paths correctly' , ( ) => {
78
+ // Mock path.resolve to return a Windows-style path
79
+ const windowsLoaderPath = 'C:\\my\\project\\dist\\config\\loaders\\valueInjectionLoader.js' ;
80
+ const pathResolveSpy = vi . spyOn ( path , 'resolve' ) ;
81
+ pathResolveSpy . mockReturnValue ( windowsLoaderPath ) ;
82
+
83
+ const userNextConfig : NextConfigObject = { } ;
84
+
85
+ const result = constructTurbopackConfig ( {
86
+ userNextConfig,
87
+ routeManifest : mockRouteManifest ,
88
+ } ) ;
89
+
90
+ expect ( result . rules ) . toBeDefined ( ) ;
91
+ expect ( result . rules ! [ '**/instrumentation-client.*' ] ) . toBeDefined ( ) ;
92
+
93
+ const rule = result . rules ! [ '**/instrumentation-client.*' ] ;
94
+ expect ( rule ) . toHaveProperty ( 'loaders' ) ;
95
+
96
+ const ruleWithLoaders = rule as { loaders : Array < { loader : string ; options : any } > } ;
97
+ expect ( ruleWithLoaders . loaders ) . toBeDefined ( ) ;
98
+ expect ( ruleWithLoaders . loaders ) . toHaveLength ( 1 ) ;
99
+
100
+ const loader = ruleWithLoaders . loaders [ 0 ] ! ;
101
+ expect ( loader ) . toHaveProperty ( 'loader' ) ;
102
+ expect ( loader ) . toHaveProperty ( 'options' ) ;
103
+ expect ( loader . options ) . toHaveProperty ( 'values' ) ;
104
+ expect ( loader . options . values ) . toHaveProperty ( '_sentryRouteManifest' ) ;
105
+ expect ( loader . loader ) . toBe ( windowsLoaderPath ) ;
106
+ expect ( pathResolveSpy ) . toHaveBeenCalledWith ( expect . any ( String ) , '..' , 'loaders' , 'valueInjectionLoader.js' ) ;
107
+
108
+ // Restore the original mock behavior
109
+ pathResolveSpy . mockReturnValue ( '/mocked/path/to/valueInjectionLoader.js' ) ;
83
110
} ) ;
84
111
} ) ;
85
112
@@ -98,7 +125,6 @@ describe('constructTurbopackConfig', () => {
98
125
99
126
const result = constructTurbopackConfig ( {
100
127
userNextConfig,
101
- userSentryOptions : mockSentryOptions ,
102
128
} ) ;
103
129
104
130
expect ( result ) . toEqual ( {
@@ -125,7 +151,6 @@ describe('constructTurbopackConfig', () => {
125
151
126
152
const result = constructTurbopackConfig ( {
127
153
userNextConfig,
128
- userSentryOptions : mockSentryOptions ,
129
154
routeManifest : mockRouteManifest ,
130
155
} ) ;
131
156
@@ -171,7 +196,6 @@ describe('constructTurbopackConfig', () => {
171
196
172
197
const result = constructTurbopackConfig ( {
173
198
userNextConfig,
174
- userSentryOptions : mockSentryOptions ,
175
199
routeManifest : mockRouteManifest ,
176
200
} ) ;
177
201
@@ -186,11 +210,10 @@ describe('constructTurbopackConfig', () => {
186
210
describe ( 'with edge cases' , ( ) => {
187
211
it ( 'should handle empty route manifest' , ( ) => {
188
212
const userNextConfig : NextConfigObject = { } ;
189
- const emptyManifest : RouteManifest = { routes : [ ] } ;
213
+ const emptyManifest : RouteManifest = { dynamicRoutes : [ ] , staticRoutes : [ ] } ;
190
214
191
215
const result = constructTurbopackConfig ( {
192
216
userNextConfig,
193
- userSentryOptions : mockSentryOptions ,
194
217
routeManifest : emptyManifest ,
195
218
} ) ;
196
219
@@ -215,15 +238,15 @@ describe('constructTurbopackConfig', () => {
215
238
it ( 'should handle complex route manifest' , ( ) => {
216
239
const userNextConfig : NextConfigObject = { } ;
217
240
const complexManifest : RouteManifest = {
218
- routes : [
241
+ dynamicRoutes : [
219
242
{ path : '/users/[id]/posts/[postId]' , regex : '/users/([^/]+)/posts/([^/]+)' , paramNames : [ 'id' , 'postId' ] } ,
220
243
{ path : '/api/[...params]' , regex : '/api/(.+)' , paramNames : [ 'params' ] } ,
221
244
] ,
245
+ staticRoutes : [ ] ,
222
246
} ;
223
247
224
248
const result = constructTurbopackConfig ( {
225
249
userNextConfig,
226
- userSentryOptions : mockSentryOptions ,
227
250
routeManifest : complexManifest ,
228
251
} ) ;
229
252
0 commit comments