@@ -7,12 +7,24 @@ import {
77 SentryWebpackPluginOptions ,
88 WebpackConfigObject ,
99} 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 ) ;
1628
1729/** Mocks of the arguments passed to `withSentryConfig` */
1830const userNextConfig = {
@@ -63,8 +75,13 @@ const clientWebpackConfig = {
6375 target : 'web' ,
6476 context : '/Users/Maisey/projects/squirrelChasingSimulator' ,
6577} ;
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 } ;
6885
6986/**
7087 * Derive the final values of all next config options, by first applying `withSentryConfig` and then, if it returns a
0 commit comments