@@ -161,3 +161,70 @@ describe('Shell Adapter', () => {
161161 } )
162162 } )
163163} )
164+
165+ describe ( 'Shell Adapter: Print human readable logging in the console when something is logged with robot.logger' , async ( ) => {
166+ it ( 'setting HUBOT_LOG_LEVEL to debug prints debug and info log messages to the console' , async ( ) => {
167+ process . env . HUBOT_LOG_LEVEL = 'debug'
168+ const robot = new Robot ( 'Shell' , false , 'TestHubot' )
169+ await robot . loadAdapter ( )
170+ await robot . run ( )
171+
172+ const old = console . log
173+ const expected = {
174+ debug : false ,
175+ info : false
176+ }
177+ console . log = ( ...args ) => {
178+ old ( ...args )
179+ switch ( true ) {
180+ case args [ 0 ] . includes ( '[debug]' ) :
181+ expected . debug = true
182+ break
183+ case args [ 0 ] . includes ( '[info]' ) :
184+ expected . info = true
185+ break
186+ }
187+ }
188+ robot . logger . debug ( 'should print debug message to console' )
189+ robot . logger . info ( 'should print info message to console' )
190+ delete process . env . HUBOT_LOG_LEVEL
191+ console . log = old
192+ assert . deepEqual ( expected , { debug : true , info : true } )
193+ robot . shutdown ( )
194+ } )
195+
196+ it ( 'setting HUBOT_LOG_LEVEL to error only prints error log messages to the console' , async ( ) => {
197+ process . env . HUBOT_LOG_LEVEL = 'error'
198+ const robot = new Robot ( 'Shell' , false , 'TestHubot' )
199+ await robot . loadAdapter ( )
200+ await robot . run ( )
201+
202+ const old = console . log
203+ const expected = {
204+ debug : false ,
205+ info : false ,
206+ error : false
207+ }
208+ console . log = ( ...args ) => {
209+ old ( ...args )
210+ switch ( true ) {
211+ case args [ 0 ] . includes ( '[debug]' ) :
212+ expected . debug = true
213+ break
214+ case args [ 0 ] . includes ( '[info]' ) :
215+ expected . info = true
216+ break
217+ case args [ 0 ] . includes ( '[error]' ) :
218+ expected . error = true
219+ break
220+ }
221+ }
222+ robot . logger . debug ( 'should NOT print debug message to console' )
223+ robot . logger . info ( 'should NOT print info message to console' )
224+ robot . logger . error ( 'should print error message to console' )
225+ delete process . env . HUBOT_LOG_LEVEL
226+ console . log = old
227+ assert . deepEqual ( expected , { debug : false , info : false , error : true } )
228+ robot . shutdown ( )
229+ } )
230+ } )
0 commit comments