@@ -7,12 +7,24 @@ import {
7
7
SentryWebpackPluginOptions ,
8
8
WebpackConfigObject ,
9
9
} from '../src/config/types' ;
10
- import {
11
- CLIENT_SDK_CONFIG_FILE ,
12
- constructWebpackConfigFunction ,
13
- SentryWebpackPlugin ,
14
- SERVER_SDK_CONFIG_FILE ,
15
- } from '../src/config/webpack' ;
10
+ import { constructWebpackConfigFunction , SentryWebpackPlugin } from '../src/config/webpack' ;
11
+
12
+ const SERVER_SDK_CONFIG_FILE = 'sentry.server.config.js' ;
13
+ const CLIENT_SDK_CONFIG_FILE = 'sentry.client.config.js' ;
14
+
15
+ // We use `fs.existsSync()` in `getUserConfigFile()`. When we're not testing `getUserConfigFile()` specifically, all we
16
+ // need is for it to give us any valid answer, so make it always find what it's looking for. Since this is a core node
17
+ // built-in, though, which jest itself uses, otherwise let it do the normal thing. Storing the real version of the
18
+ // function also lets us restore the original when we do want to test `getUserConfigFile()`.
19
+ const realExistsSync = jest . requireActual ( 'fs' ) . existsSync ;
20
+ const mockExistsSync = ( path : fs . PathLike ) => {
21
+ if ( ( path as string ) . endsWith ( SERVER_SDK_CONFIG_FILE ) || ( path as string ) . endsWith ( CLIENT_SDK_CONFIG_FILE ) ) {
22
+ return true ;
23
+ }
24
+
25
+ return realExistsSync ( path ) ;
26
+ } ;
27
+ const exitsSync = jest . spyOn ( fs , 'existsSync' ) . mockImplementation ( mockExistsSync ) ;
16
28
17
29
/** Mocks of the arguments passed to `withSentryConfig` */
18
30
const userNextConfig = {
@@ -63,8 +75,13 @@ const clientWebpackConfig = {
63
75
target : 'web' ,
64
76
context : '/Users/Maisey/projects/squirrelChasingSimulator' ,
65
77
} ;
66
- const serverBuildContext = { isServer : true , dev : false , buildId : 'doGsaREgReaT' } ;
67
- const clientBuildContext = { isServer : false , dev : false , buildId : 'doGsaREgReaT' } ;
78
+ const baseBuildContext = {
79
+ dev : false ,
80
+ buildId : 'doGsaREgReaT' ,
81
+ dir : '/Users/Maisey/projects/squirrelChasingSimulator' ,
82
+ } ;
83
+ const serverBuildContext = { isServer : true , ...baseBuildContext } ;
84
+ const clientBuildContext = { isServer : false , ...baseBuildContext } ;
68
85
69
86
/**
70
87
* Derive the final values of all next config options, by first applying `withSentryConfig` and then, if it returns a
@@ -223,6 +240,9 @@ describe('webpack config', () => {
223
240
} ) ;
224
241
225
242
describe ( 'webpack `entry` property config' , ( ) => {
243
+ const serverConfigFilePath = `./${ SERVER_SDK_CONFIG_FILE } ` ;
244
+ const clientConfigFilePath = `./${ CLIENT_SDK_CONFIG_FILE } ` ;
245
+
226
246
it ( 'handles various entrypoint shapes' , async ( ) => {
227
247
const finalWebpackConfig = await materializeFinalWebpackConfig ( {
228
248
userNextConfig,
@@ -234,23 +254,23 @@ describe('webpack config', () => {
234
254
expect . objectContaining ( {
235
255
// original entry point value is a string
236
256
// (was 'private-next-pages/api/dogs/[name].js')
237
- 'pages/api/dogs/[name]' : [ SERVER_SDK_CONFIG_FILE , 'private-next-pages/api/dogs/[name].js' ] ,
257
+ 'pages/api/dogs/[name]' : [ serverConfigFilePath , 'private-next-pages/api/dogs/[name].js' ] ,
238
258
239
259
// original entry point value is a string array
240
260
// (was ['./node_modules/smellOVision/index.js', 'private-next-pages/_app.js'])
241
- 'pages/_app' : [ SERVER_SDK_CONFIG_FILE , './node_modules/smellOVision/index.js' , 'private-next-pages/_app.js' ] ,
261
+ 'pages/_app' : [ serverConfigFilePath , './node_modules/smellOVision/index.js' , 'private-next-pages/_app.js' ] ,
242
262
243
263
// original entry point value is an object containing a string `import` value
244
264
// (`import` was 'private-next-pages/api/simulator/dogStats/[name].js')
245
265
'pages/api/simulator/dogStats/[name]' : {
246
- import : [ SERVER_SDK_CONFIG_FILE , 'private-next-pages/api/simulator/dogStats/[name].js' ] ,
266
+ import : [ serverConfigFilePath , 'private-next-pages/api/simulator/dogStats/[name].js' ] ,
247
267
} ,
248
268
249
269
// original entry point value is an object containing a string array `import` value
250
270
// (`import` was ['./node_modules/dogPoints/converter.js', 'private-next-pages/api/simulator/leaderboard.js'])
251
271
'pages/api/simulator/leaderboard' : {
252
272
import : [
253
- SERVER_SDK_CONFIG_FILE ,
273
+ serverConfigFilePath ,
254
274
'./node_modules/dogPoints/converter.js' ,
255
275
'private-next-pages/api/simulator/leaderboard.js' ,
256
276
] ,
@@ -259,7 +279,7 @@ describe('webpack config', () => {
259
279
// original entry point value is an object containg properties besides `import`
260
280
// (`dependOn` remains untouched)
261
281
'pages/api/tricks/[trickName]' : {
262
- import : [ SERVER_SDK_CONFIG_FILE , 'private-next-pages/api/tricks/[trickName].js' ] ,
282
+ import : [ serverConfigFilePath , 'private-next-pages/api/tricks/[trickName].js' ] ,
263
283
dependOn : 'treats' ,
264
284
} ,
265
285
} ) ,
@@ -278,7 +298,7 @@ describe('webpack config', () => {
278
298
// no injected file
279
299
main : './src/index.ts' ,
280
300
// was 'next-client-pages-loader?page=%2F_app'
281
- 'pages/_app' : [ CLIENT_SDK_CONFIG_FILE , 'next-client-pages-loader?page=%2F_app' ] ,
301
+ 'pages/_app' : [ clientConfigFilePath , 'next-client-pages-loader?page=%2F_app' ] ,
282
302
} ) ,
283
303
) ;
284
304
} ) ;
0 commit comments