53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { initSentry } from './sentry';
|
|
|
|
describe('sentry', () => {
|
|
const originalEnv = process.env;
|
|
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
process.env = { ...originalEnv };
|
|
console.error = jest.fn();
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
describe('initSentry', () => {
|
|
it('should not initialize Sentry in non-production environment', () => {
|
|
process.env.NODE_ENV = 'development';
|
|
process.env.NEXT_PUBLIC_SENTRY_DSN = 'test-dsn';
|
|
|
|
initSentry();
|
|
|
|
expect(console.error).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should not initialize Sentry when DSN is not set', () => {
|
|
process.env.NODE_ENV = 'production';
|
|
process.env.NEXT_PUBLIC_SENTRY_DSN = '';
|
|
|
|
initSentry();
|
|
|
|
expect(console.error).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should initialize Sentry in production with DSN', () => {
|
|
process.env.NODE_ENV = 'production';
|
|
process.env.NEXT_PUBLIC_SENTRY_DSN = 'https://test@sentry.io/123';
|
|
|
|
initSentry();
|
|
|
|
expect(console.error).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle missing NODE_ENV gracefully', () => {
|
|
delete process.env.NODE_ENV;
|
|
process.env.NEXT_PUBLIC_SENTRY_DSN = 'https://test@sentry.io/123';
|
|
|
|
initSentry();
|
|
|
|
expect(console.error).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
}); |