Skip to content

Commit 286f009

Browse files
committed
update tests
1 parent 6db152d commit 286f009

1 file changed

Lines changed: 46 additions & 48 deletions

File tree

packages/core/test/lib/integrations/consola.test.ts

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('createConsolaReporter', () => {
6262
});
6363

6464
describe('message and args handling', () => {
65-
it('should format message from args when message is not provided', () => {
65+
it('should format message from args', () => {
6666
const logObj = {
6767
type: 'info',
6868
args: ['Hello', 'world', 123, { key: 'value' }],
@@ -101,6 +101,51 @@ describe('createConsolaReporter', () => {
101101
},
102102
});
103103
});
104+
105+
it('consola-merged: args=[message] with extra keys on log object', () => {
106+
sentryReporter.log({
107+
type: 'log',
108+
level: 2,
109+
args: ['Hello', 'world', { some: 'obj' }],
110+
userId: 123,
111+
action: 'login',
112+
time: '2026-02-24T10:24:04.477Z',
113+
smallObj: { firstLevel: { secondLevel: { thirdLevel: { fourthLevel: 'deep' } } } },
114+
tag: '',
115+
});
116+
117+
const call = vi.mocked(_INTERNAL_captureLog).mock.calls[0]![0];
118+
119+
// Message from args
120+
expect(call.message).toBe('Hello world {"some":"obj"}');
121+
expect(call.attributes).toMatchObject({
122+
'consola.type': 'log',
123+
'consola.level': 2,
124+
userId: 123,
125+
smallObj: { firstLevel: { secondLevel: { thirdLevel: '[Object]' } } }, // Object is normalized
126+
action: 'login',
127+
time: '2026-02-24T10:24:04.477Z',
128+
'sentry.origin': 'auto.log.consola',
129+
});
130+
expect(call.attributes?.['sentry.message.parameter.0']).toBeUndefined();
131+
});
132+
133+
it('capturing custom keys mimicking direct reporter.log({ type, message, userId, sessionId })', () => {
134+
sentryReporter.log({
135+
type: 'info',
136+
message: 'User action',
137+
userId: 123,
138+
sessionId: 'abc-123',
139+
});
140+
141+
const call = vi.mocked(_INTERNAL_captureLog).mock.calls[0]![0];
142+
expect(call.message).toBe('User action');
143+
expect(call.attributes).toMatchObject({
144+
'consola.type': 'info',
145+
userId: 123,
146+
sessionId: 'abc-123',
147+
});
148+
});
104149
});
105150

106151
describe('level mapping', () => {
@@ -207,51 +252,4 @@ describe('createConsolaReporter', () => {
207252
expect(_INTERNAL_captureLog).toHaveBeenCalledTimes(6);
208253
});
209254
});
210-
211-
describe('message and args handling', () => {
212-
it('consola-merged: args=[message] with extra keys on log object', () => {
213-
sentryReporter.log({
214-
type: 'log',
215-
level: 2,
216-
args: ['Hello', 'world', { some: 'obj' }],
217-
userId: 123,
218-
action: 'login',
219-
time: '2026-02-24T10:24:04.477Z',
220-
smallObj: { firstLevel: { secondLevel: { thirdLevel: { fourthLevel: 'deep' } } } },
221-
tag: '',
222-
});
223-
224-
const call = vi.mocked(_INTERNAL_captureLog).mock.calls[0]![0];
225-
226-
// Message from args
227-
expect(call.message).toBe('Hello world {"some":"obj"}');
228-
expect(call.attributes).toMatchObject({
229-
'consola.type': 'log',
230-
'consola.level': 2,
231-
userId: 123,
232-
smallObj: { firstLevel: { secondLevel: { thirdLevel: '[Object]' } } }, // Object is normalized
233-
action: 'login',
234-
time: '2026-02-24T10:24:04.477Z',
235-
'sentry.origin': 'auto.log.consola',
236-
});
237-
expect(call.attributes?.['sentry.message.parameter.0']).toBeUndefined();
238-
});
239-
240-
it('capturing custom keys mimicking `log({ message: "", ... })` or direct reporter.log({ type, message, userId, sessionId })', () => {
241-
sentryReporter.log({
242-
type: 'info',
243-
message: 'User action',
244-
userId: 123,
245-
sessionId: 'abc-123',
246-
});
247-
248-
const call = vi.mocked(_INTERNAL_captureLog).mock.calls[0]![0];
249-
expect(call.message).toBe('User action');
250-
expect(call.attributes).toMatchObject({
251-
'consola.type': 'info',
252-
userId: 123,
253-
sessionId: 'abc-123',
254-
});
255-
});
256-
});
257255
});

0 commit comments

Comments
 (0)