Skip to content

Commit c166bbc

Browse files
committed
add unit tests
1 parent 75744da commit c166bbc

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

packages/node-core/test/logs/exports.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as sentryCore from '@sentry/core';
22
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
33
import * as nodeLogger from '../../src/logs/exports';
4+
import { Scope } from '@sentry/core';
45

56
// Mock the core functions
67
vi.mock('@sentry/core', async () => {
@@ -172,4 +173,50 @@ describe('Node Logger', () => {
172173
);
173174
});
174175
});
176+
177+
describe('scustom cope', () => {
178+
it('calls _INTERNAL_captureLog with custom scope for basic log message', () => {
179+
const customScope = new Scope();
180+
nodeLogger.debug('User logged in', undefined, { scope: customScope });
181+
expect(mockCaptureLog).toHaveBeenCalledWith(
182+
{
183+
level: 'debug',
184+
message: 'User logged in',
185+
},
186+
customScope,
187+
);
188+
});
189+
190+
it('calls _INTERNAL_captureLog with custom scope for parametrized log message', () => {
191+
const customScope = new Scope();
192+
nodeLogger.debug('User %s logged in from %s', ['Alice', 'mobile'], undefined, { scope: customScope });
193+
expect(mockCaptureLog).toHaveBeenCalledWith(
194+
{
195+
level: 'debug',
196+
message: 'User Alice logged in from mobile',
197+
attributes: {
198+
'sentry.message.template': 'User %s logged in from %s',
199+
'sentry.message.parameter.0': 'Alice',
200+
'sentry.message.parameter.1': 'mobile',
201+
},
202+
},
203+
customScope,
204+
);
205+
});
206+
207+
it('calls _INTERNAL_captureLog with custom scope for fmt log message', () => {
208+
const customScope = new Scope();
209+
nodeLogger.debug(nodeLogger.fmt`User ${'Alice'} logged in from ${'mobile'}`, undefined, { scope: customScope });
210+
expect(mockCaptureLog).toHaveBeenCalledWith(
211+
{
212+
level: 'debug',
213+
message: expect.objectContaining({
214+
__sentry_template_string__: 'User %s logged in from %s',
215+
__sentry_template_values__: ['Alice', 'mobile'],
216+
}),
217+
},
218+
customScope,
219+
);
220+
});
221+
});
175222
});

0 commit comments

Comments
 (0)