@@ -2,51 +2,60 @@ import { createLogger } from "../../src/sentry/logger";
2
2
3
3
describe ( "Logger" , ( ) => {
4
4
const consoleErrorSpy = jest . spyOn ( console , "error" ) . mockImplementation ( ( ) => undefined ) ;
5
+ const consoleInfoSpy = jest . spyOn ( console , "info" ) . mockImplementation ( ( ) => undefined ) ;
6
+ const consoleWarnSpy = jest . spyOn ( console , "warn" ) . mockImplementation ( ( ) => undefined ) ;
7
+ const consoleDebugSpy = jest . spyOn ( console , "debug" ) . mockImplementation ( ( ) => undefined ) ;
5
8
6
9
afterEach ( ( ) => {
7
10
consoleErrorSpy . mockReset ( ) ;
11
+ consoleInfoSpy . mockReset ( ) ;
12
+ consoleWarnSpy . mockReset ( ) ;
13
+ consoleDebugSpy . mockReset ( ) ;
8
14
} ) ;
9
15
10
16
it . each ( [
11
- [ "info" , "Info" ] ,
12
- [ "warn" , "Warning" ] ,
13
- [ "error" , "Error" ] ,
14
- ] as const ) ( ".%s() should log correctly" , ( loggerMethod , logLevel ) => {
17
+ [ "info" , "Info" , consoleInfoSpy ] ,
18
+ [ "warn" , "Warning" , consoleWarnSpy ] ,
19
+ [ "error" , "Error" , consoleErrorSpy ] ,
20
+ ] as const ) ( ".%s() should log correctly" , ( loggerMethod , logLevel , consoleSpy ) => {
15
21
const prefix = "[some-prefix]" ;
16
22
const logger = createLogger ( { prefix, silent : false , debug : true } ) ;
17
23
18
24
logger [ loggerMethod ] ( "Hey!" ) ;
19
25
20
- expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( `[some-prefix] ${ logLevel } : Hey!` ) ;
26
+ expect ( consoleSpy ) . toHaveBeenCalledWith ( `[some-prefix] ${ logLevel } : Hey!` ) ;
21
27
} ) ;
22
28
23
29
it . each ( [
24
- [ "info" , "Info" ] ,
25
- [ "warn" , "Warning" ] ,
26
- [ "error" , "Error" ] ,
27
- ] as const ) ( ".%s() should log multiple params correctly" , ( loggerMethod , logLevel ) => {
28
- const prefix = "[some-prefix]" ;
29
- const logger = createLogger ( { prefix, silent : false , debug : true } ) ;
30
+ [ "info" , "Info" , consoleInfoSpy ] ,
31
+ [ "warn" , "Warning" , consoleWarnSpy ] ,
32
+ [ "error" , "Error" , consoleErrorSpy ] ,
33
+ ] as const ) (
34
+ ".%s() should log multiple params correctly" ,
35
+ ( loggerMethod , logLevel , consoleSpy ) => {
36
+ const prefix = "[some-prefix]" ;
37
+ const logger = createLogger ( { prefix, silent : false , debug : true } ) ;
30
38
31
- logger [ loggerMethod ] ( "Hey!" , "this" , "is" , "a test with" , 5 , "params" ) ;
39
+ logger [ loggerMethod ] ( "Hey!" , "this" , "is" , "a test with" , 5 , "params" ) ;
32
40
33
- expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
34
- `[some-prefix] ${ logLevel } : Hey!` ,
35
- "this" ,
36
- "is" ,
37
- "a test with" ,
38
- 5 ,
39
- "params"
40
- ) ;
41
- } ) ;
41
+ expect ( consoleSpy ) . toHaveBeenCalledWith (
42
+ `[some-prefix] ${ logLevel } : Hey!` ,
43
+ "this" ,
44
+ "is" ,
45
+ "a test with" ,
46
+ 5 ,
47
+ "params"
48
+ ) ;
49
+ }
50
+ ) ;
42
51
43
52
it ( ".debug() should log correctly" , ( ) => {
44
53
const prefix = "[some-prefix]" ;
45
54
const logger = createLogger ( { prefix, silent : false , debug : true } ) ;
46
55
47
56
logger . debug ( "Hey!" ) ;
48
57
49
- expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( `[some-prefix] Debug: Hey!` ) ;
58
+ expect ( consoleDebugSpy ) . toHaveBeenCalledWith ( `[some-prefix] Debug: Hey!` ) ;
50
59
} ) ;
51
60
52
61
it ( ".debug() should log multiple params correctly" , ( ) => {
@@ -55,7 +64,7 @@ describe("Logger", () => {
55
64
56
65
logger . debug ( "Hey!" , "this" , "is" , "a test with" , 5 , "params" ) ;
57
66
58
- expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
67
+ expect ( consoleDebugSpy ) . toHaveBeenCalledWith (
59
68
`[some-prefix] Debug: Hey!` ,
60
69
"this" ,
61
70
"is" ,
@@ -66,13 +75,17 @@ describe("Logger", () => {
66
75
} ) ;
67
76
68
77
describe ( "doesn't log when `silent` option is `true`" , ( ) => {
69
- it . each ( [ "info" , "warn" , "error" ] as const ) ( ".%s()" , ( loggerMethod ) => {
78
+ it . each ( [
79
+ [ "info" , consoleInfoSpy ] ,
80
+ [ "warn" , consoleWarnSpy ] ,
81
+ [ "error" , consoleErrorSpy ] ,
82
+ ] as const ) ( ".%s()" , ( loggerMethod , consoleSpy ) => {
70
83
const prefix = "[some-prefix]" ;
71
84
const logger = createLogger ( { prefix, silent : true , debug : true } ) ;
72
85
73
86
logger [ loggerMethod ] ( "Hey!" ) ;
74
87
75
- expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( ) ;
88
+ expect ( consoleSpy ) . not . toHaveBeenCalled ( ) ;
76
89
} ) ;
77
90
} ) ;
78
91
@@ -82,6 +95,6 @@ describe("Logger", () => {
82
95
83
96
logger . debug ( "Hey!" ) ;
84
97
85
- expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( ) ;
98
+ expect ( consoleDebugSpy ) . not . toHaveBeenCalled ( ) ;
86
99
} ) ;
87
100
} ) ;
0 commit comments