Skip to main content
Glama
SentryService.test.ts1.6 kB
import * as Sentry from '@sentry/node'; import { SentryService } from '../SentryService'; jest.mock('@sentry/node', () => { const originalSentry = jest.requireActual('@sentry/node'); return { ...originalSentry, init: jest.fn(), captureException: jest.fn(), withScope: jest.fn(callback => callback({ setContext: jest.fn() })), }; }); jest.mock('@sentry/profiling-node', () => ({ nodeProfilingIntegration: jest.fn(() => ({ name: 'ProfilingIntegration' })), })); describe('SentryService', () => { beforeEach(() => { // Reset the service state before each test (SentryService as any).resetForTesting(); }); afterEach(() => { jest.clearAllMocks(); }); describe('initialize', () => { it('should initialize Sentry if DSN is provided', () => { process.env.SENTRY_DSN = 'https://test@sentry.io/123'; SentryService.initialize(); expect(Sentry.init).toHaveBeenCalledWith(expect.objectContaining({ dsn: 'https://test@sentry.io/123', })); }); it('should not initialize Sentry if DSN is not provided', () => { delete process.env.SENTRY_DSN; SentryService.initialize(); expect(Sentry.init).not.toHaveBeenCalled(); }); }); describe('captureException', () => { it('should capture an exception with context', () => { const error = new Error('Test error'); const context = { userId: '123' }; SentryService.captureException(error, context); expect(Sentry.captureException).toHaveBeenCalledWith(error); expect(Sentry.withScope).toHaveBeenCalled(); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/learnwithcc/tally-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server