@@ -2,13 +2,22 @@ import { logger } from '../src/index';
22
33describe ( 'Logger' , ( ) => {
44 let consoleLogSpy : jest . SpyInstance ;
5+ let consoleWarnSpy : jest . SpyInstance ;
6+ let consoleErrorSpy : jest . SpyInstance ;
7+ let consoleDebugSpy : jest . SpyInstance ;
58
69 beforeEach ( ( ) => {
710 consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
11+ consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ) ;
12+ consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
13+ consoleDebugSpy = jest . spyOn ( console , 'debug' ) . mockImplementation ( ) ;
814 } ) ;
915
1016 afterEach ( ( ) => {
1117 consoleLogSpy . mockRestore ( ) ;
18+ consoleWarnSpy . mockRestore ( ) ;
19+ consoleErrorSpy . mockRestore ( ) ;
20+ consoleDebugSpy . mockRestore ( ) ;
1221 } ) ;
1322
1423 it ( "should log a message when NODE_ENV is not 'production'" , ( ) => {
@@ -30,4 +39,64 @@ describe('Logger', () => {
3039
3140 expect ( consoleLogSpy ) . not . toHaveBeenCalled ( ) ;
3241 } ) ;
42+
43+ it ( "should warn a message when NODE_ENV is not 'production'" , ( ) => {
44+ process . env . NODE_ENV = 'development' ;
45+ const message = 'Test warn message' ;
46+
47+ logger . warn ( message ) ;
48+
49+ 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 / )
51+ ) ;
52+ } ) ;
53+
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'" , ( ) => {
64+ process . env . NODE_ENV = 'development' ;
65+ const message = 'Test error message' ;
66+
67+ logger . error ( message ) ;
68+
69+ 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 / )
71+ ) ;
72+ } ) ;
73+
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'" , ( ) => {
84+ process . env . NODE_ENV = 'development' ;
85+ const message = 'Test debug message' ;
86+
87+ logger . debug ( message ) ;
88+
89+ 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 / )
91+ ) ;
92+ } ) ;
93+
94+ it ( "should not debug a message when NODE_ENV is 'production'" , ( ) => {
95+ process . env . NODE_ENV = 'production' ;
96+ const message = 'Test debug message' ;
97+
98+ logger . debug ( message ) ;
99+
100+ expect ( consoleDebugSpy ) . not . toHaveBeenCalled ( ) ;
101+ } ) ;
33102} ) ;
0 commit comments