@@ -23,6 +23,13 @@ import {
2323import { setupDecoratorLambdaHandler } from '../helpers/metricsUtils.js' ;
2424import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js' ;
2525
26+ jest . mock ( 'node:console' , ( ) => ( {
27+ ...jest . requireActual ( 'node:console' ) ,
28+ Console : jest . fn ( ) . mockImplementation ( ( ) => ( {
29+ log : jest . fn ( ) ,
30+ } ) ) ,
31+ } ) ) ;
32+ jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => ( { } ) ) ;
2633const mockDate = new Date ( 1466424490000 ) ;
2734const dateSpy = jest . spyOn ( global , 'Date' ) . mockImplementation ( ( ) => mockDate ) ;
2835jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
@@ -235,6 +242,9 @@ describe('Class: Metrics', () => {
235242 getServiceName ( ) : string {
236243 return 'test-service' ;
237244 } ,
245+ isDevMode ( ) : boolean {
246+ return false ;
247+ } ,
238248 } ;
239249 const metricsOptions : MetricsOptions = {
240250 customConfigService : configService ,
@@ -699,7 +709,7 @@ describe('Class: Metrics', () => {
699709 test ( 'it should publish metrics when the array of values reaches the maximum size' , ( ) => {
700710 // Prepare
701711 const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
702- const consoleSpy = jest . spyOn ( console , 'log' ) ;
712+ const consoleSpy = jest . spyOn ( metrics [ ' console' ] , 'log' ) ;
703713 const metricName = 'test-metric' ;
704714
705715 // Act
@@ -1242,7 +1252,9 @@ describe('Class: Metrics', () => {
12421252 // Prepare
12431253 const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
12441254 metrics . addMetric ( 'test-metric' , MetricUnit . Count , 10 ) ;
1245- const consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
1255+ const consoleLogSpy = jest
1256+ . spyOn ( metrics [ 'console' ] , 'log' )
1257+ . mockImplementation ( ) ;
12461258 const mockData : EmfOutput = {
12471259 _aws : {
12481260 Timestamp : mockDate . getTime ( ) ,
@@ -1512,7 +1524,7 @@ describe('Class: Metrics', () => {
15121524 } ) ;
15131525
15141526 // Act
1515- metrics . addMetric ( testMetric , MetricUnits . Count , 10 ) ;
1527+ metrics . addMetric ( testMetric , MetricUnit . Count , 10 ) ;
15161528 metrics . addDimension ( 'foo' , 'baz' ) ;
15171529 const loggedData = metrics . serializeMetrics ( ) ;
15181530
@@ -1531,7 +1543,7 @@ describe('Class: Metrics', () => {
15311543 Metrics : [
15321544 {
15331545 Name : testMetric ,
1534- Unit : MetricUnits . Count ,
1546+ Unit : MetricUnit . Count ,
15351547 } ,
15361548 ] ,
15371549 Namespace : TEST_NAMESPACE ,
@@ -2179,4 +2191,15 @@ describe('Class: Metrics', () => {
21792191 ) ;
21802192 } ) ;
21812193 } ) ;
2194+
2195+ describe ( 'Feature: POWERTOOLS_DEV' , ( ) => {
2196+ it ( 'uses the global console object when the environment variable is set' , ( ) => {
2197+ // Prepare
2198+ process . env . POWERTOOLS_DEV = 'true' ;
2199+ const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
2200+
2201+ // Act & Assess
2202+ expect ( metrics [ 'console' ] ) . toEqual ( console ) ;
2203+ } ) ;
2204+ } ) ;
21822205} ) ;
0 commit comments