Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

logger.test.ts 1.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  1. import {
  2. setLogCallback,
  3. getLogLevel,
  4. setLogLevel,
  5. LOG_LEVELS,
  6. globalLogCallback,
  7. } from '../src/logger';
  8. describe('logger', () => {
  9. beforeEach(() => {
  10. setLogCallback(null);
  11. });
  12. describe('setLogCallback', () => {
  13. it('should set the global log callback', () => {
  14. const callback = jest.fn();
  15. setLogCallback(callback);
  16. expect(globalLogCallback).toBe(callback);
  17. });
  18. it('should allow setting null callback', () => {
  19. setLogCallback(null);
  20. expect(globalLogCallback).toBeNull();
  21. });
  22. });
  23. describe('getLogLevel', () => {
  24. it('should return current log level', () => {
  25. const level = getLogLevel();
  26. expect(Object.keys(LOG_LEVELS)).toContain(level);
  27. });
  28. });
  29. describe('setLogLevel', () => {
  30. it('should set valid log levels', () => {
  31. setLogLevel('debug');
  32. expect(getLogLevel()).toBe('debug');
  33. setLogLevel('info');
  34. expect(getLogLevel()).toBe('info');
  35. setLogLevel('warn');
  36. expect(getLogLevel()).toBe('warn');
  37. setLogLevel('error');
  38. expect(getLogLevel()).toBe('error');
  39. });
  40. it('should throw error for invalid log level', () => {
  41. // @ts-expect-error Testing invalid input
  42. expect(() => setLogLevel('invalid')).toThrow('Invalid log level: invalid');
  43. });
  44. });
  45. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...