@@ -30,15 +30,19 @@ const CLIENT_SDK_CONFIG_FILE = 'sentry.client.config.js';
30
30
// 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
31
31
// built-in, though, which jest itself uses, otherwise let it do the normal thing. Storing the real version of the
32
32
// function also lets us restore the original when we do want to test `getUserConfigFile()`.
33
- const realExistsSync = jest . requireActual ( 'fs' ) . existsSync ;
34
- const mockExistsSync = ( path : fs . PathLike ) => {
33
+ const realFs = {
34
+ existsSync : jest . requireActual ( 'fs' ) . existsSync ,
35
+ mkdtempSync : jest . requireActual ( 'fs' ) . mkdtempSync ,
36
+ writeFileSync : jest . requireActual ( 'fs' ) . writeFileSync ,
37
+ } ;
38
+ jest . mock ( 'fs' ) ;
39
+ const existsSyncMockImplementation = ( path : fs . PathLike ) => {
35
40
if ( ( path as string ) . endsWith ( SERVER_SDK_CONFIG_FILE ) || ( path as string ) . endsWith ( CLIENT_SDK_CONFIG_FILE ) ) {
36
41
return true ;
37
42
}
38
-
39
- return realExistsSync ( path ) ;
43
+ return realFs . existsSync ( path ) ;
40
44
} ;
41
- const exitsSync = jest . spyOn ( fs , 'existsSync' ) . mockImplementation ( mockExistsSync ) ;
45
+ jest . spyOn ( fs , 'existsSync' ) . mockImplementation ( existsSyncMockImplementation ) ;
42
46
43
47
/** Mocks of the arguments passed to `withSentryConfig` */
44
48
const userNextConfig : Partial < NextConfigObject > = {
@@ -328,7 +332,7 @@ describe('webpack config', () => {
328
332
} ) ;
329
333
} ) ;
330
334
331
- describe . only ( '`distDir` value in default server-side `RewriteFrames` integration' , ( ) => {
335
+ describe ( '`distDir` value in default server-side `RewriteFrames` integration' , ( ) => {
332
336
describe ( '`DefinePlugin` existence and inclusion of `__rewriteFramesDistDir__` definition' , ( ) => {
333
337
it . each ( [
334
338
[ 'no custom `distDir`, pre-existing `DefinePlugin`' , undefined , true ] ,
@@ -353,10 +357,8 @@ describe('webpack config', () => {
353
357
incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigMaybeWithDistDir ) ,
354
358
} ) ;
355
359
356
- expect ( finalWebpackConfig . plugins ) . toEqual ( expect . arrayContaining ( [ expect . any ( DefinePlugin ) ] ) ) ;
357
-
358
360
const definePluginInstance = findWebpackPlugin ( finalWebpackConfig , 'DefinePlugin' ) as DefinePlugin ;
359
- expect ( definePluginInstance . definitions . __rewriteFramesDistDir__ ) . toEqual ( customDistDir ) ;
361
+ expect ( definePluginInstance . definitions . __rewriteFramesDistDir__ ) . toStrictEqual ( customDistDir ) ;
360
362
} ,
361
363
) ;
362
364
} ) ;
@@ -622,37 +624,33 @@ describe('Sentry webpack plugin config', () => {
622
624
describe ( 'getUserConfigFile' , ( ) => {
623
625
let tempDir : string ;
624
626
625
- beforeAll ( ( ) => {
626
- exitsSync . mockImplementation ( realExistsSync ) ;
627
- } ) ;
627
+ beforeAll ( ( ) => jest . spyOn ( fs , 'existsSync' ) . mockImplementation ( realFs . existsSync ) ) ;
628
628
629
629
beforeEach ( ( ) => {
630
630
const tempDirPathPrefix = path . join ( os . tmpdir ( ) , 'sentry-nextjs-test-' ) ;
631
- tempDir = fs . mkdtempSync ( tempDirPathPrefix ) ;
631
+ tempDir = realFs . mkdtempSync ( tempDirPathPrefix ) ;
632
632
} ) ;
633
633
634
634
afterEach ( ( ) => {
635
635
rimraf . sync ( tempDir ) ;
636
636
} ) ;
637
637
638
- afterAll ( ( ) => {
639
- exitsSync . mockImplementation ( mockExistsSync ) ;
640
- } ) ;
638
+ afterAll ( ( ) => jest . spyOn ( fs , 'existsSync' ) . mockImplementation ( existsSyncMockImplementation ) ) ;
641
639
642
640
it ( 'successfully finds js files' , ( ) => {
643
- fs . writeFileSync ( path . resolve ( tempDir , 'sentry.server.config.js' ) , 'Dogs are great!' ) ;
644
- fs . writeFileSync ( path . resolve ( tempDir , 'sentry.client.config.js' ) , 'Squirrel!' ) ;
641
+ realFs . writeFileSync ( path . resolve ( tempDir , 'sentry.server.config.js' ) , 'Dogs are great!' ) ;
642
+ realFs . writeFileSync ( path . resolve ( tempDir , 'sentry.client.config.js' ) , 'Squirrel!' ) ;
645
643
646
- expect ( getUserConfigFile ( tempDir , 'server' ) ) . toEqual ( 'sentry.server.config.js' ) ;
647
- expect ( getUserConfigFile ( tempDir , 'client' ) ) . toEqual ( 'sentry.client.config.js' ) ;
644
+ expect ( getUserConfigFile ( tempDir , 'server' ) ) . toStrictEqual ( 'sentry.server.config.js' ) ;
645
+ expect ( getUserConfigFile ( tempDir , 'client' ) ) . toStrictEqual ( 'sentry.client.config.js' ) ;
648
646
} ) ;
649
647
650
648
it ( 'successfully finds ts files' , ( ) => {
651
- fs . writeFileSync ( path . resolve ( tempDir , 'sentry.server.config.ts' ) , 'Sit. Stay. Lie Down.' ) ;
652
- fs . writeFileSync ( path . resolve ( tempDir , 'sentry.client.config.ts' ) , 'Good dog!' ) ;
649
+ realFs . writeFileSync ( path . resolve ( tempDir , 'sentry.server.config.ts' ) , 'Sit. Stay. Lie Down.' ) ;
650
+ realFs . writeFileSync ( path . resolve ( tempDir , 'sentry.client.config.ts' ) , 'Good dog!' ) ;
653
651
654
- expect ( getUserConfigFile ( tempDir , 'server' ) ) . toEqual ( 'sentry.server.config.ts' ) ;
655
- expect ( getUserConfigFile ( tempDir , 'client' ) ) . toEqual ( 'sentry.client.config.ts' ) ;
652
+ expect ( getUserConfigFile ( tempDir , 'server' ) ) . toStrictEqual ( 'sentry.server.config.ts' ) ;
653
+ expect ( getUserConfigFile ( tempDir , 'client' ) ) . toStrictEqual ( 'sentry.client.config.ts' ) ;
656
654
} ) ;
657
655
658
656
it ( 'errors when files are missing' , ( ) => {
0 commit comments