@@ -1430,6 +1430,29 @@ describe('Class: Metrics', () => {
1430
1430
expect ( consoleLogSpy ) . toBeCalledWith ( JSON . stringify ( mockData ) ) ;
1431
1431
} ) ;
1432
1432
1433
+ test ( 'it should not log anything if metrics are disabled' , ( ) => {
1434
+ // Prepare
1435
+ process . env . POWERTOOLS_METRICS_DISABLED = 'true' ;
1436
+ const customLogger = {
1437
+ log : jest . fn ( ) ,
1438
+ warn : jest . fn ( ) ,
1439
+ debug : jest . fn ( ) ,
1440
+ error : jest . fn ( ) ,
1441
+ info : jest . fn ( ) ,
1442
+ } ;
1443
+ const metrics : Metrics = new Metrics ( {
1444
+ namespace : TEST_NAMESPACE ,
1445
+ logger : customLogger ,
1446
+ } ) ;
1447
+ const consoleLogSpy = jest . spyOn ( customLogger , 'log' ) ;
1448
+
1449
+ // Act
1450
+ metrics . publishStoredMetrics ( ) ;
1451
+
1452
+ // Assess
1453
+ expect ( consoleLogSpy ) . toHaveBeenCalledTimes ( 0 ) ;
1454
+ } ) ;
1455
+
1433
1456
test ( 'it should call clearMetrics function' , ( ) => {
1434
1457
// Prepare
1435
1458
const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
@@ -2355,6 +2378,54 @@ describe('Class: Metrics', () => {
2355
2378
} ) ;
2356
2379
} ) ;
2357
2380
2381
+ describe ( 'Method: isDisabled' , ( ) => {
2382
+ it ( 'should be enabled by default' , ( ) => {
2383
+ const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
2384
+
2385
+ // Act & Assess
2386
+ // biome-ignore lint/complexity/useLiteralKeys: accessing protected method
2387
+ expect ( metrics [ 'isDisabled' ] ( ) ) . toBe ( false ) ;
2388
+ } ) ;
2389
+
2390
+ it ( 'should be disabled if POWERTOOLS_DEV is set to true' , ( ) => {
2391
+ process . env . POWERTOOLS_DEV = 'true' ;
2392
+ const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
2393
+
2394
+ // Act & Assess
2395
+ // biome-ignore lint/complexity/useLiteralKeys: accessing protected method
2396
+ expect ( metrics [ 'isDisabled' ] ( ) ) . toBe ( true ) ;
2397
+ } ) ;
2398
+
2399
+ it ( 'should be disabled if POWERTOOLS_METRICS_DISABLED is set to true' , ( ) => {
2400
+ // Prepare
2401
+ process . env . POWERTOOLS_METRICS_DISABLED = 'true' ;
2402
+ const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
2403
+
2404
+ // Act & Assess
2405
+ // biome-ignore lint/complexity/useLiteralKeys: accessing protected method
2406
+ expect ( metrics [ 'isDisabled' ] ( ) ) . toBe ( true ) ;
2407
+ } ) ;
2408
+
2409
+ it ( 'should be enabled if POWERTOOLS_METRICS_DISABLED is set to false' , ( ) => {
2410
+ process . env . POWERTOOLS_METRICS_DISABLED = 'false' ;
2411
+ const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
2412
+
2413
+ // Act & Assess
2414
+ // biome-ignore lint/complexity/useLiteralKeys: accessing protected method
2415
+ expect ( metrics [ 'isDisabled' ] ( ) ) . toBe ( false ) ;
2416
+ } ) ;
2417
+
2418
+ it ( 'should be enabled if POWERTOOLS_DEV is set to true and POWERTOOLS_METRICS_DISABLED is set to false' , ( ) => {
2419
+ process . env . POWERTOOLS_DEV = 'true' ;
2420
+ process . env . POWERTOOLS_METRICS_DISABLED = 'false' ;
2421
+ const metrics : Metrics = new Metrics ( { namespace : TEST_NAMESPACE } ) ;
2422
+
2423
+ // Act & Assess
2424
+ // biome-ignore lint/complexity/useLiteralKeys: accessing protected method
2425
+ expect ( metrics [ 'isDisabled' ] ( ) ) . toBe ( false ) ;
2426
+ } ) ;
2427
+ } ) ;
2428
+
2358
2429
describe ( 'Method: setTimestamp' , ( ) => {
2359
2430
const testCases = [
2360
2431
{
0 commit comments