@@ -24,6 +24,13 @@ import {
24
24
EnvironmentVariablesService ,
25
25
} from '../../src/config' ;
26
26
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 ( ( ) => ( { } ) ) ;
27
34
const mockDate = new Date ( 1466424490000 ) ;
28
35
const dateSpy = jest . spyOn ( global , 'Date' ) . mockImplementation ( ( ) => mockDate ) ;
29
36
jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
@@ -234,6 +241,9 @@ describe('Class: Metrics', () => {
234
241
getServiceName ( ) : string {
235
242
return 'test-service' ;
236
243
} ,
244
+ isDevMode ( ) : boolean {
245
+ return false ;
246
+ } ,
237
247
} ;
238
248
const metricsOptions : MetricsOptions = {
239
249
customConfigService : configService ,
@@ -703,7 +713,7 @@ describe('Class: Metrics', () => {
703
713
test ( 'it should publish metrics when the array of values reaches the maximum size' , ( ) => {
704
714
// Prepare
705
715
const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
706
- const consoleSpy = jest . spyOn ( console , 'log' ) ;
716
+ const consoleSpy = jest . spyOn ( metrics [ ' console' ] , 'log' ) ;
707
717
const metricName = 'test-metric' ;
708
718
709
719
// Act
@@ -1246,7 +1256,9 @@ describe('Class: Metrics', () => {
1246
1256
// Prepare
1247
1257
const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
1248
1258
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 ( ) ;
1250
1262
const mockData : EmfOutput = {
1251
1263
_aws : {
1252
1264
Timestamp : mockDate . getTime ( ) ,
@@ -2183,4 +2195,15 @@ describe('Class: Metrics', () => {
2183
2195
) ;
2184
2196
} ) ;
2185
2197
} ) ;
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
+ } ) ;
2186
2209
} ) ;
0 commit comments