Skip to content

Commit fcfd91c

Browse files
committed
add integration tests
1 parent 9293805 commit fcfd91c

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
import { consola } from 'consola';
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
release: '1.0.0',
8+
environment: 'test',
9+
enableLogs: true,
10+
transport: loggingTransport,
11+
});
12+
13+
async function run(): Promise<void> {
14+
consola.level = 5;
15+
const sentryReporter = Sentry.createConsolaReporter();
16+
consola.addReporter(sentryReporter);
17+
18+
// Object-first: args = [object, string] — first object becomes attributes, second arg is part of formatted message
19+
consola.info({ userId: 100, action: 'login' }, 'User logged in');
20+
21+
// Object-first: args = [object] only — object keys become attributes, message is stringified object
22+
consola.info({ event: 'click', count: 2 });
23+
24+
await Sentry.flush();
25+
}
26+
27+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
28+
void run();

dev-packages/node-integration-tests/suites/consola/test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,55 @@ describe('consola integration', () => {
491491

492492
await runner.completed();
493493
});
494+
495+
test('should capture object-first consola logs (object as first arg)', async () => {
496+
const runner = createRunner(__dirname, 'subject-object-first.ts')
497+
.expect({
498+
log: {
499+
items: [
500+
{
501+
timestamp: expect.any(Number),
502+
level: 'info',
503+
body: '{"userId":100,"action":"login"} User logged in',
504+
severity_number: expect.any(Number),
505+
trace_id: expect.any(String),
506+
attributes: {
507+
'sentry.origin': { value: 'auto.log.consola', type: 'string' },
508+
'sentry.release': { value: '1.0.0', type: 'string' },
509+
'sentry.environment': { value: 'test', type: 'string' },
510+
'sentry.sdk.name': { value: 'sentry.javascript.node', type: 'string' },
511+
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
512+
'server.address': { value: expect.any(String), type: 'string' },
513+
'consola.type': { value: 'info', type: 'string' },
514+
'consola.level': { value: 3, type: 'integer' },
515+
userId: { value: 100, type: 'integer' },
516+
action: { value: 'login', type: 'string' },
517+
},
518+
},
519+
{
520+
timestamp: expect.any(Number),
521+
level: 'info',
522+
body: '{"event":"click","count":2}',
523+
severity_number: expect.any(Number),
524+
trace_id: expect.any(String),
525+
attributes: {
526+
'sentry.origin': { value: 'auto.log.consola', type: 'string' },
527+
'sentry.release': { value: '1.0.0', type: 'string' },
528+
'sentry.environment': { value: 'test', type: 'string' },
529+
'sentry.sdk.name': { value: 'sentry.javascript.node', type: 'string' },
530+
'sentry.sdk.version': { value: expect.any(String), type: 'string' },
531+
'server.address': { value: expect.any(String), type: 'string' },
532+
'consola.type': { value: 'info', type: 'string' },
533+
'consola.level': { value: 3, type: 'integer' },
534+
event: { value: 'click', type: 'string' },
535+
count: { value: 2, type: 'integer' },
536+
},
537+
},
538+
],
539+
},
540+
})
541+
.start();
542+
543+
await runner.completed();
544+
});
494545
});

0 commit comments

Comments
 (0)