|
1 | 1 | import * as sentryCore from '@sentry/core'; |
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
3 | 3 | import * as nodeLogger from '../../src/logs/exports'; |
| 4 | +import { Scope } from '@sentry/core'; |
4 | 5 |
|
5 | 6 | // Mock the core functions |
6 | 7 | vi.mock('@sentry/core', async () => { |
@@ -172,4 +173,50 @@ describe('Node Logger', () => { |
172 | 173 | ); |
173 | 174 | }); |
174 | 175 | }); |
| 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 | + }); |
175 | 222 | }); |
0 commit comments