@@ -20,83 +20,78 @@ describe('Logger', () => {
2020 consoleDebugSpy . mockRestore ( ) ;
2121 } ) ;
2222
23- it ( "should log a message when NODE_ENV is not 'production'" , ( ) => {
23+ it ( "should log a message with an optional parameter when NODE_ENV is not 'production'" , ( ) => {
2424 process . env . NODE_ENV = 'development' ;
2525 const message = 'Test log message' ;
26+ const additionalParam = { key : 'value' } ;
2627
27- logger . log ( message ) ;
28+ logger . log ( message , additionalParam ) ;
2829
2930 expect ( consoleLogSpy ) . toHaveBeenCalledWith (
30- expect . stringMatching ( / \[ L O G \] .* : T e s t l o g m e s s a g e / )
31+ expect . stringMatching ( / \[ L O G \] .* : T e s t l o g m e s s a g e \{ " k e y " : " v a l u e " \} / )
3132 ) ;
3233 } ) ;
3334
34- it ( "should not log a message when NODE_ENV is 'production'" , ( ) => {
35- process . env . NODE_ENV = 'production ' ;
35+ it ( "should log a message without an optional parameter when NODE_ENV is not 'production'" , ( ) => {
36+ process . env . NODE_ENV = 'development ' ;
3637 const message = 'Test log message' ;
3738
3839 logger . log ( message ) ;
3940
40- expect ( consoleLogSpy ) . not . toHaveBeenCalled ( ) ;
41+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
42+ expect . stringMatching ( / \[ L O G \] .* : T e s t l o g m e s s a g e / )
43+ ) ;
4144 } ) ;
4245
43- it ( "should warn a message when NODE_ENV is not 'production'" , ( ) => {
46+ it ( "should warn a message with an optional parameter when NODE_ENV is not 'production'" , ( ) => {
4447 process . env . NODE_ENV = 'development' ;
4548 const message = 'Test warn message' ;
49+ const additionalParam = [ 1 , 2 , 3 ] ;
4650
47- logger . warn ( message ) ;
51+ logger . warn ( message , additionalParam ) ;
4852
4953 expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
50- expect . stringMatching ( / \[ W A R N \] .* : T e s t w a r n m e s s a g e / )
54+ expect . stringMatching ( / \[ W A R N \] .* : T e s t w a r n m e s s a g e \[ 1 , 2 , 3 \] / )
5155 ) ;
5256 } ) ;
5357
54- it ( "should not warn a message when NODE_ENV is 'production'" , ( ) => {
55- process . env . NODE_ENV = 'production' ;
56- const message = 'Test warn message' ;
57-
58- logger . warn ( message ) ;
59-
60- expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( ) ;
61- } ) ;
62-
63- it ( "should error a message when NODE_ENV is not 'production'" , ( ) => {
58+ it ( "should error a message with an optional parameter when NODE_ENV is not 'production'" , ( ) => {
6459 process . env . NODE_ENV = 'development' ;
6560 const message = 'Test error message' ;
61+ const additionalParam = 'extra details' ;
6662
67- logger . error ( message ) ;
63+ logger . error ( message , additionalParam ) ;
6864
6965 expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
70- expect . stringMatching ( / \[ E R R O R \] .* : T e s t e r r o r m e s s a g e / )
66+ expect . stringMatching ( / \[ E R R O R \] .* : T e s t e r r o r m e s s a g e e x t r a d e t a i l s / )
7167 ) ;
7268 } ) ;
7369
74- it ( "should not error a message when NODE_ENV is 'production'" , ( ) => {
75- process . env . NODE_ENV = 'production' ;
76- const message = 'Test error message' ;
77-
78- logger . error ( message ) ;
79-
80- expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( ) ;
81- } ) ;
82-
83- it ( "should debug a message when NODE_ENV is not 'production'" , ( ) => {
70+ it ( "should debug a message with an optional parameter when NODE_ENV is not 'production'" , ( ) => {
8471 process . env . NODE_ENV = 'development' ;
8572 const message = 'Test debug message' ;
73+ const additionalParam = { debug : true } ;
8674
87- logger . debug ( message ) ;
75+ logger . debug ( message , additionalParam ) ;
8876
8977 expect ( consoleDebugSpy ) . toHaveBeenCalledWith (
90- expect . stringMatching ( / \[ D E B U G \] .* : T e s t d e b u g m e s s a g e / )
78+ expect . stringMatching ( / \[ D E B U G \] .* : T e s t d e b u g m e s s a g e \{ " d e b u g " : t r u e \} / )
9179 ) ;
9280 } ) ;
9381
94- it ( "should not debug a message when NODE_ENV is 'production'" , ( ) => {
82+ it ( "should not log, warn, error, or debug a message when NODE_ENV is 'production'" , ( ) => {
9583 process . env . NODE_ENV = 'production' ;
96- const message = 'Test debug message' ;
84+ const message = 'Test message' ;
85+ const additionalParam = { ignored : true } ;
9786
98- logger . debug ( message ) ;
87+ logger . log ( message , additionalParam ) ;
88+ logger . warn ( message , additionalParam ) ;
89+ logger . error ( message , additionalParam ) ;
90+ logger . debug ( message , additionalParam ) ;
9991
92+ expect ( consoleLogSpy ) . not . toHaveBeenCalled ( ) ;
93+ expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( ) ;
94+ expect ( consoleErrorSpy ) . not . toHaveBeenCalled ( ) ;
10095 expect ( consoleDebugSpy ) . not . toHaveBeenCalled ( ) ;
10196 } ) ;
10297} ) ;
0 commit comments