@@ -24,6 +24,13 @@ import {
2424 EnvironmentVariablesService ,
2525} from '../../src/config' ;
2626
27+ jest . mock ( 'node:console' , ( ) => ( {
28+ ...jest . requireActual ( 'node:console' ) ,
29+ Console : jest . fn ( ) . mockImplementation ( ( ) => ( {
30+ log : jest . fn ( ) ,
31+ } ) ) ,
32+ } ) ) ;
33+ jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => ( { } ) ) ;
2734const mockDate = new Date ( 1466424490000 ) ;
2835const dateSpy = jest . spyOn ( global , 'Date' ) . mockImplementation ( ( ) => mockDate ) ;
2936jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
@@ -234,6 +241,9 @@ describe('Class: Metrics', () => {
234241 getServiceName ( ) : string {
235242 return 'test-service' ;
236243 } ,
244+ isDevMode ( ) : boolean {
245+ return false ;
246+ } ,
237247 } ;
238248 const metricsOptions : MetricsOptions = {
239249 customConfigService : configService ,
@@ -703,7 +713,7 @@ describe('Class: Metrics', () => {
703713 test ( 'it should publish metrics when the array of values reaches the maximum size' , ( ) => {
704714 // Prepare
705715 const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
706- const consoleSpy = jest . spyOn ( console , 'log' ) ;
716+ const consoleSpy = jest . spyOn ( metrics [ ' console' ] , 'log' ) ;
707717 const metricName = 'test-metric' ;
708718
709719 // Act
@@ -1246,7 +1256,9 @@ describe('Class: Metrics', () => {
12461256 // Prepare
12471257 const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
12481258 metrics . addMetric ( 'test-metric' , MetricUnits . Count , 10 ) ;
1249- const consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
1259+ const consoleLogSpy = jest
1260+ . spyOn ( metrics [ 'console' ] , 'log' )
1261+ . mockImplementation ( ) ;
12501262 const mockData : EmfOutput = {
12511263 _aws : {
12521264 Timestamp : mockDate . getTime ( ) ,
@@ -2183,4 +2195,15 @@ describe('Class: Metrics', () => {
21832195 ) ;
21842196 } ) ;
21852197 } ) ;
2198+
2199+ describe ( 'Feature: POWERTOOLS_DEV' , ( ) => {
2200+ it ( 'uses the global console object when the environment variable is set' , ( ) => {
2201+ // Prepare
2202+ process . env . POWERTOOLS_DEV = 'true' ;
2203+ const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
2204+
2205+ // Act & Assess
2206+ expect ( metrics [ 'console' ] ) . toEqual ( console ) ;
2207+ } ) ;
2208+ } ) ;
21862209} ) ;
0 commit comments