@@ -57,11 +57,10 @@ afterAll(() => {
5757// In order to know what to expect in the webpack config `entry` property, we need to know the path of the temporary
5858// directory created when doing the file injection, so wrap the real `mkdtempSync` and store the resulting path where we
5959// can access it
60- let tempDir : string ;
61- const realMkdtempSync = jest . requireActual ( 'fs' ) . mkdtempSync ;
62- jest . spyOn ( fs , 'mkdtempSync' ) . mockImplementation ( prefix => {
63- tempDir = realMkdtempSync ( prefix ) ;
64- return tempDir ;
60+ const mkdtempSyncSpy = jest . spyOn ( fs , 'mkdtempSync' ) ;
61+
62+ afterEach ( ( ) => {
63+ mkdtempSyncSpy . mockClear ( ) ;
6564} ) ;
6665
6766/** Mocks of the arguments passed to `withSentryConfig` */
@@ -311,6 +310,7 @@ describe('webpack config', () => {
311310 incomingWebpackBuildContext : serverBuildContext ,
312311 } ) ;
313312
313+ const tempDir = mkdtempSyncSpy . mock . results [ 0 ] . value ;
314314 const rewriteFramesHelper = path . join ( tempDir , 'rewriteFramesHelper.js' ) ;
315315
316316 expect ( finalWebpackConfig . entry ) . toEqual (
@@ -405,6 +405,8 @@ describe('webpack config', () => {
405405 incomingWebpackConfig : serverWebpackConfig ,
406406 incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigDistDir ) ,
407407 } ) ;
408+
409+ const tempDir = mkdtempSyncSpy . mock . results [ 0 ] . value ;
408410 const rewriteFramesHelper = path . join ( tempDir , 'rewriteFramesHelper.js' ) ;
409411
410412 expect ( fs . existsSync ( rewriteFramesHelper ) ) . toBe ( true ) ;
@@ -668,6 +670,8 @@ describe('Sentry webpack plugin config', () => {
668670 } ) ;
669671
670672 describe ( 'getUserConfigFile' , ( ) => {
673+ let tempDir : string ;
674+
671675 beforeAll ( ( ) => {
672676 exitsSync . mockImplementation ( realExistsSync ) ;
673677 } ) ;
@@ -677,6 +681,7 @@ describe('Sentry webpack plugin config', () => {
677681 // that the location of the created folder is stored in `tempDir`
678682 const tempDirPathPrefix = path . join ( os . tmpdir ( ) , 'sentry-nextjs-test-' ) ;
679683 fs . mkdtempSync ( tempDirPathPrefix ) ;
684+ tempDir = mkdtempSyncSpy . mock . results [ 0 ] . value ;
680685 } ) ;
681686
682687 afterAll ( ( ) => {
0 commit comments