Skip to content

Commit 7df528a

Browse files
Fix config.test.ts
1 parent b1e9535 commit 7df528a

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

packages/nextjs/test/config.test.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ const CLIENT_SDK_CONFIG_FILE = 'sentry.client.config.js';
3030
// 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
3131
// built-in, though, which jest itself uses, otherwise let it do the normal thing. Storing the real version of the
3232
// 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) => {
3540
if ((path as string).endsWith(SERVER_SDK_CONFIG_FILE) || (path as string).endsWith(CLIENT_SDK_CONFIG_FILE)) {
3641
return true;
3742
}
38-
39-
return realExistsSync(path);
43+
return realFs.existsSync(path);
4044
};
41-
const exitsSync = jest.spyOn(fs, 'existsSync').mockImplementation(mockExistsSync);
45+
jest.spyOn(fs, 'existsSync').mockImplementation(existsSyncMockImplementation);
4246

4347
/** Mocks of the arguments passed to `withSentryConfig` */
4448
const userNextConfig: Partial<NextConfigObject> = {
@@ -328,7 +332,7 @@ describe('webpack config', () => {
328332
});
329333
});
330334

331-
describe.only('`distDir` value in default server-side `RewriteFrames` integration', () => {
335+
describe('`distDir` value in default server-side `RewriteFrames` integration', () => {
332336
describe('`DefinePlugin` existence and inclusion of `__rewriteFramesDistDir__` definition', () => {
333337
it.each([
334338
['no custom `distDir`, pre-existing `DefinePlugin`', undefined, true],
@@ -353,10 +357,8 @@ describe('webpack config', () => {
353357
incomingWebpackBuildContext: getBuildContext('server', userNextConfigMaybeWithDistDir),
354358
});
355359

356-
expect(finalWebpackConfig.plugins).toEqual(expect.arrayContaining([expect.any(DefinePlugin)]));
357-
358360
const definePluginInstance = findWebpackPlugin(finalWebpackConfig, 'DefinePlugin') as DefinePlugin;
359-
expect(definePluginInstance.definitions.__rewriteFramesDistDir__).toEqual(customDistDir);
361+
expect(definePluginInstance.definitions.__rewriteFramesDistDir__).toStrictEqual(customDistDir);
360362
},
361363
);
362364
});
@@ -622,37 +624,33 @@ describe('Sentry webpack plugin config', () => {
622624
describe('getUserConfigFile', () => {
623625
let tempDir: string;
624626

625-
beforeAll(() => {
626-
exitsSync.mockImplementation(realExistsSync);
627-
});
627+
beforeAll(() => jest.spyOn(fs, 'existsSync').mockImplementation(realFs.existsSync));
628628

629629
beforeEach(() => {
630630
const tempDirPathPrefix = path.join(os.tmpdir(), 'sentry-nextjs-test-');
631-
tempDir = fs.mkdtempSync(tempDirPathPrefix);
631+
tempDir = realFs.mkdtempSync(tempDirPathPrefix);
632632
});
633633

634634
afterEach(() => {
635635
rimraf.sync(tempDir);
636636
});
637637

638-
afterAll(() => {
639-
exitsSync.mockImplementation(mockExistsSync);
640-
});
638+
afterAll(() => jest.spyOn(fs, 'existsSync').mockImplementation(existsSyncMockImplementation));
641639

642640
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!');
645643

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');
648646
});
649647

650648
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!');
653651

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');
656654
});
657655

658656
it('errors when files are missing', () => {

0 commit comments

Comments
 (0)