Skip to content

Commit 7fef657

Browse files
committed
tests: add unit tests
1 parent 73261f1 commit 7fef657

File tree

2 files changed

+115
-179
lines changed

2 files changed

+115
-179
lines changed

packages/logger/tests/unit/repro.test.ts

-179
This file was deleted.

packages/logger/tests/unit/workingWithkeys.test.ts

+115
Original file line numberDiff line numberDiff line change
@@ -620,4 +620,119 @@ describe('Working with keys', () => {
620620
})
621621
);
622622
});
623+
624+
it("doesn't overwrite standard keys when appending keys", () => {
625+
// Prepare
626+
const logger = new Logger();
627+
628+
// Act
629+
logger.appendKeys({
630+
level: 'Hello, World!',
631+
});
632+
logger.info('foo');
633+
634+
// Assess
635+
expect(console.info).toHaveLoggedNth(
636+
1,
637+
expect.objectContaining({
638+
level: 'INFO',
639+
})
640+
);
641+
expect(console.warn).toHaveLoggedNth(
642+
1,
643+
expect.objectContaining({
644+
message: 'The key "level" is a reserved key and will be dropped.',
645+
})
646+
);
647+
});
648+
649+
it("doesn't overwrite standard keys when appending persistent keys", () => {
650+
// Prepare
651+
const logger = new Logger();
652+
653+
// Act
654+
logger.appendPersistentKeys({
655+
timestamp: 'Hello, World!',
656+
});
657+
logger.info('foo');
658+
659+
// Assess
660+
expect(console.info).toHaveLoggedNth(
661+
1,
662+
expect.objectContaining({
663+
timestamp: expect.not.stringMatching('Hello, World!'),
664+
})
665+
);
666+
expect(console.warn).toHaveLoggedNth(
667+
1,
668+
expect.objectContaining({
669+
message: 'The key "timestamp" is a reserved key and will be dropped.',
670+
})
671+
);
672+
});
673+
674+
it("doesn't overwrite standard keys when appending keys via constructor", () => {
675+
// Prepare
676+
const logger = new Logger({
677+
persistentKeys: {
678+
sampling_rate: 'Hello, World!',
679+
},
680+
});
681+
682+
// Act
683+
logger.info('foo');
684+
685+
// Assess
686+
expect(console.info).toHaveLoggedNth(
687+
1,
688+
expect.objectContaining({
689+
sampling_rate: expect.not.stringMatching('Hello, World!'),
690+
})
691+
);
692+
expect(console.warn).toHaveLoggedNth(
693+
1,
694+
expect.objectContaining({
695+
message:
696+
'The key "sampling_rate" is a reserved key and will be dropped.',
697+
})
698+
);
699+
});
700+
701+
it("doesn't overwrite standard keys when passing keys to log method", () => {
702+
// Prepare
703+
const logger = new Logger();
704+
705+
// Act
706+
logger.info(
707+
{
708+
message: 'foo',
709+
timestamp: 'Hello, World!',
710+
},
711+
{
712+
level: 'Hello, World!',
713+
}
714+
);
715+
716+
// Assess
717+
expect(console.info).toHaveLoggedNth(
718+
1,
719+
expect.objectContaining({
720+
message: 'foo',
721+
timestamp: expect.not.stringMatching('Hello, World!'),
722+
level: 'INFO',
723+
})
724+
);
725+
expect(console.warn).toHaveLoggedNth(
726+
1,
727+
expect.objectContaining({
728+
message: 'The key "timestamp" is a reserved key and will be dropped.',
729+
})
730+
);
731+
expect(console.warn).toHaveLoggedNth(
732+
2,
733+
expect.objectContaining({
734+
message: 'The key "level" is a reserved key and will be dropped.',
735+
})
736+
);
737+
});
623738
});

0 commit comments

Comments
 (0)