diff --git a/packages/metrics/package.json b/packages/metrics/package.json index 6dc3ec7901..6a85b8d43e 100644 --- a/packages/metrics/package.json +++ b/packages/metrics/package.json @@ -19,8 +19,8 @@ "build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", "build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json", "build": "npm run build:esm & npm run build:cjs", - "lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .", - "lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .", + "lint": "biome lint .", + "lint:fix": "biome check --write .", "prepack": "node ../../.github/scripts/release_patch_package_json.js ." }, "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/metrics#readme", @@ -52,10 +52,7 @@ "lib/cjs/middleware/middy.d.ts", "lib/esm/middleware/middy.d.ts" ], - "types": [ - "lib/cjs/types/index.d.ts", - "lib/esm/types/index.d.ts" - ] + "types": ["lib/cjs/types/index.d.ts", "lib/esm/types/index.d.ts"] } }, "types": "./lib/cjs/index.d.ts", @@ -74,9 +71,7 @@ "optional": true } }, - "files": [ - "lib" - ], + "files": ["lib"], "repository": { "type": "git", "url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git" @@ -87,12 +82,5 @@ "dependencies": { "@aws-lambda-powertools/commons": "^2.5.0" }, - "keywords": [ - "aws", - "lambda", - "powertools", - "metrics", - "serverless", - "nodejs" - ] + "keywords": ["aws", "lambda", "powertools", "metrics", "serverless", "nodejs"] } diff --git a/packages/metrics/src/Metrics.ts b/packages/metrics/src/Metrics.ts index 5b828379b3..72f5a37bf5 100644 --- a/packages/metrics/src/Metrics.ts +++ b/packages/metrics/src/Metrics.ts @@ -1,28 +1,28 @@ -import type { Callback, Context, Handler } from 'aws-lambda'; import { Console } from 'node:console'; import { Utility } from '@aws-lambda-powertools/commons'; import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types'; +import type { Callback, Context, Handler } from 'aws-lambda'; import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js'; import { + COLD_START_METRIC, + DEFAULT_NAMESPACE, MAX_DIMENSION_COUNT, MAX_METRICS_SIZE, - DEFAULT_NAMESPACE, - COLD_START_METRIC, MAX_METRIC_VALUES_SIZE, - MetricUnit as MetricUnits, MetricResolution as MetricResolutions, + MetricUnit as MetricUnits, } from './constants.js'; -import { - type MetricsOptions, - type Dimensions, - type EmfOutput, - type StoredMetrics, - type ExtraOptions, - type MetricDefinition, - type ConfigServiceInterface, - type MetricsInterface, - type MetricUnit, - type MetricResolution, +import type { + ConfigServiceInterface, + Dimensions, + EmfOutput, + ExtraOptions, + MetricDefinition, + MetricResolution, + MetricUnit, + MetricsInterface, + MetricsOptions, + StoredMetrics, } from './types/index.js'; /** @@ -167,9 +167,9 @@ class Metrics extends Utility implements MetricsInterface { */ public addDimensions(dimensions: { [key: string]: string }): void { const newDimensions = { ...this.dimensions }; - Object.keys(dimensions).forEach((dimensionName) => { + for (const dimensionName of Object.keys(dimensions)) { newDimensions[dimensionName] = dimensions[dimensionName]; - }); + } if (Object.keys(newDimensions).length > MAX_DIMENSION_COUNT) { throw new RangeError( `Unable to add ${ @@ -337,10 +337,7 @@ class Metrics extends Utility implements MetricsInterface { } return (_target, _propertyKey, descriptor) => { - /** - * The descriptor.value is the method this decorator decorates, it cannot be undefined. - */ - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + // biome-ignore lint/style/noNonNullAssertion: The descriptor.value is the method this decorator decorates, it cannot be undefined. const originalMethod = descriptor.value!; // eslint-disable-next-line @typescript-eslint/no-this-alias @@ -359,8 +356,6 @@ class Metrics extends Utility implements MetricsInterface { let result: unknown; try { result = await originalMethod.apply(this, [event, context, callback]); - } catch (error) { - throw error; } finally { metricsRef.publishStoredMetrics(); } @@ -598,9 +593,8 @@ class Metrics extends Utility implements MetricsInterface { } return false; - } else { - return true; } + return true; } /** diff --git a/packages/metrics/src/config/EnvironmentVariablesService.ts b/packages/metrics/src/config/EnvironmentVariablesService.ts index 7ec51b9e7f..8894faf6f8 100644 --- a/packages/metrics/src/config/EnvironmentVariablesService.ts +++ b/packages/metrics/src/config/EnvironmentVariablesService.ts @@ -1,5 +1,5 @@ -import type { ConfigServiceInterface } from '../types/ConfigServiceInterface.js'; import { EnvironmentVariablesService as CommonEnvironmentVariablesService } from '@aws-lambda-powertools/commons'; +import type { ConfigServiceInterface } from '../types/ConfigServiceInterface.js'; class EnvironmentVariablesService extends CommonEnvironmentVariablesService diff --git a/packages/metrics/src/middleware/middy.ts b/packages/metrics/src/middleware/middy.ts index 57744b45df..a3d401fcdd 100644 --- a/packages/metrics/src/middleware/middy.ts +++ b/packages/metrics/src/middleware/middy.ts @@ -1,10 +1,10 @@ import { METRICS_KEY } from '@aws-lambda-powertools/commons'; -import type { Metrics } from '../Metrics.js'; -import type { ExtraOptions } from '../types/Metrics.js'; import type { MiddlewareLikeObj, MiddyLikeRequest, } from '@aws-lambda-powertools/commons/types'; +import type { Metrics } from '../Metrics.js'; +import type { ExtraOptions } from '../types/Metrics.js'; /** * A middy middleware automating capture of metadata and annotations on segments or subsegments for a Lambda Handler. @@ -38,7 +38,7 @@ const logMetrics = ( target: Metrics | Metrics[], options: ExtraOptions = {} ): MiddlewareLikeObj => { - const metricsInstances = target instanceof Array ? target : [target]; + const metricsInstances = Array.isArray(target) ? target : [target]; /** * Set the cleanup function to be called in case other middlewares return early. @@ -53,7 +53,7 @@ const logMetrics = ( }; const logMetricsBefore = async (request: MiddyLikeRequest): Promise => { - metricsInstances.forEach((metrics: Metrics) => { + for (const metrics of metricsInstances) { metrics.setFunctionName(request.context.functionName); const { throwOnEmptyMetrics, defaultDimensions, captureColdStartMetric } = options; @@ -66,15 +66,15 @@ const logMetrics = ( if (captureColdStartMetric) { metrics.captureColdStartMetric(); } - }); + } setCleanupFunction(request); }; const logMetricsAfterOrError = async (): Promise => { - metricsInstances.forEach((metrics: Metrics) => { + for (const metrics of metricsInstances) { metrics.publishStoredMetrics(); - }); + } }; return { diff --git a/packages/metrics/src/types/Metrics.ts b/packages/metrics/src/types/Metrics.ts index a8780bca10..3b0a163134 100644 --- a/packages/metrics/src/types/Metrics.ts +++ b/packages/metrics/src/types/Metrics.ts @@ -1,5 +1,8 @@ +import type { + MetricResolution as MetricResolutionList, + MetricUnit as MetricUnitList, +} from '../constants.js'; import type { ConfigServiceInterface } from './ConfigServiceInterface.js'; -import { MetricResolution, MetricUnit } from '../constants.js'; type Dimensions = Record; @@ -49,9 +52,9 @@ type ExtraOptions = { }; type MetricResolution = - (typeof MetricResolution)[keyof typeof MetricResolution]; + (typeof MetricResolutionList)[keyof typeof MetricResolutionList]; -type MetricUnit = (typeof MetricUnit)[keyof typeof MetricUnit]; +type MetricUnit = (typeof MetricUnitList)[keyof typeof MetricUnitList]; type StoredMetric = { name: string; diff --git a/packages/metrics/src/types/MetricsInterface.ts b/packages/metrics/src/types/MetricsInterface.ts index c4e796cf98..ccc3e9f7c5 100644 --- a/packages/metrics/src/types/MetricsInterface.ts +++ b/packages/metrics/src/types/MetricsInterface.ts @@ -1,11 +1,11 @@ -import type { Metrics } from '../Metrics.js'; import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types'; +import type { Metrics } from '../Metrics.js'; import type { - EmfOutput, Dimensions, - MetricsOptions, + EmfOutput, MetricResolution, MetricUnit, + MetricsOptions, } from './Metrics.js'; interface MetricsInterface { diff --git a/packages/metrics/tests/e2e/basicFeatures.decorator.test.functionCode.ts b/packages/metrics/tests/e2e/basicFeatures.decorator.test.functionCode.ts index 15e8da2a3d..9122abeea7 100644 --- a/packages/metrics/tests/e2e/basicFeatures.decorator.test.functionCode.ts +++ b/packages/metrics/tests/e2e/basicFeatures.decorator.test.functionCode.ts @@ -1,7 +1,7 @@ -import { Metrics, MetricUnit } from '../../src/index.js'; -import type { MetricUnit as MetricUnitType } from '../../src/types/index.js'; -import type { Context } from 'aws-lambda'; import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; +import type { Context } from 'aws-lambda'; +import { MetricUnit, Metrics } from '../../src/index.js'; +import type { MetricUnit as MetricUnitType } from '../../src/types/index.js'; const namespace = process.env.EXPECTED_NAMESPACE ?? 'CdkExample'; const serviceName = @@ -35,7 +35,7 @@ class Lambda implements LambdaInterface { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore public async handler(_event: unknown, _context: Context): Promise { - metrics.addMetric(metricName, metricUnit, parseInt(metricValue)); + metrics.addMetric(metricName, metricUnit, Number.parseInt(metricValue)); metrics.addDimension( Object.entries(JSON.parse(extraDimension))[0][0], Object.entries(JSON.parse(extraDimension))[0][1] as string @@ -54,7 +54,7 @@ class Lambda implements LambdaInterface { metricWithItsOwnDimensions.addMetric( singleMetricName, singleMetricUnit, - parseInt(singleMetricValue) + Number.parseInt(singleMetricValue) ); } } diff --git a/packages/metrics/tests/e2e/basicFeatures.decorators.test.ts b/packages/metrics/tests/e2e/basicFeatures.decorators.test.ts index 7ad7258916..08b70d5154 100644 --- a/packages/metrics/tests/e2e/basicFeatures.decorators.test.ts +++ b/packages/metrics/tests/e2e/basicFeatures.decorators.test.ts @@ -3,27 +3,27 @@ * * @group e2e/metrics/decorator */ +import { join } from 'node:path'; import { - invokeFunction, TestStack, + invokeFunction, } from '@aws-lambda-powertools/testing-utils'; import { CloudWatchClient, GetMetricStatisticsCommand, } from '@aws-sdk/client-cloudwatch'; -import { join } from 'node:path'; import { getMetrics, sortDimensions } from '../helpers/metricsUtils.js'; import { MetricsTestNodejsFunction } from '../helpers/resources.js'; import { - commonEnvironmentVars, ONE_MINUTE, RESOURCE_NAME_PREFIX, SETUP_TIMEOUT, TEARDOWN_TIMEOUT, TEST_CASE_TIMEOUT, + commonEnvironmentVars, } from './constants.js'; -describe(`Metrics E2E tests, basic features decorator usage`, () => { +describe('Metrics E2E tests, basic features decorator usage', () => { const testStack = new TestStack({ stackNameProps: { stackNamePrefix: RESOURCE_NAME_PREFIX, @@ -205,7 +205,7 @@ describe(`Metrics E2E tests, basic features decorator usage`, () => { ? metricStat.Datapoints[0] : {}; expect(singleDataPoint?.Sum).toBeGreaterThanOrEqual( - parseInt(expectedMetricValue) * invocations + Number.parseInt(expectedMetricValue) * invocations ); }, TEST_CASE_TIMEOUT diff --git a/packages/metrics/tests/e2e/basicFeatures.manual.test.functionCode.ts b/packages/metrics/tests/e2e/basicFeatures.manual.test.functionCode.ts index 8c06579e34..4091a2691a 100644 --- a/packages/metrics/tests/e2e/basicFeatures.manual.test.functionCode.ts +++ b/packages/metrics/tests/e2e/basicFeatures.manual.test.functionCode.ts @@ -1,6 +1,6 @@ -import { Metrics, MetricUnit } from '../../src/index.js'; -import type { MetricUnit as MetricUnitType } from '../../src/types/index.js'; import type { Context } from 'aws-lambda'; +import { MetricUnit, Metrics } from '../../src/index.js'; +import type { MetricUnit as MetricUnitType } from '../../src/types/index.js'; const namespace = process.env.EXPECTED_NAMESPACE ?? 'CdkExample'; const serviceName = @@ -32,7 +32,7 @@ export const handler = async ( metrics.captureColdStartMetric(); metrics.throwOnEmptyMetrics(); metrics.setDefaultDimensions(JSON.parse(defaultDimensions)); - metrics.addMetric(metricName, metricUnit, parseInt(metricValue)); + metrics.addMetric(metricName, metricUnit, Number.parseInt(metricValue)); metrics.addDimension( Object.entries(JSON.parse(extraDimension))[0][0], Object.entries(JSON.parse(extraDimension))[0][1] as string @@ -46,7 +46,7 @@ export const handler = async ( metricWithItsOwnDimensions.addMetric( singleMetricName, singleMetricUnit, - parseInt(singleMetricValue) + Number.parseInt(singleMetricValue) ); metrics.publishStoredMetrics(); diff --git a/packages/metrics/tests/e2e/basicFeatures.manual.test.ts b/packages/metrics/tests/e2e/basicFeatures.manual.test.ts index 8211d6c882..b37fc374b7 100644 --- a/packages/metrics/tests/e2e/basicFeatures.manual.test.ts +++ b/packages/metrics/tests/e2e/basicFeatures.manual.test.ts @@ -3,27 +3,27 @@ * * @group e2e/metrics/standardFunctions */ +import { join } from 'node:path'; import { - invokeFunction, TestStack, + invokeFunction, } from '@aws-lambda-powertools/testing-utils'; import { CloudWatchClient, GetMetricStatisticsCommand, } from '@aws-sdk/client-cloudwatch'; -import { join } from 'node:path'; import { getMetrics, sortDimensions } from '../helpers/metricsUtils.js'; import { MetricsTestNodejsFunction } from '../helpers/resources.js'; import { - commonEnvironmentVars, ONE_MINUTE, RESOURCE_NAME_PREFIX, SETUP_TIMEOUT, TEARDOWN_TIMEOUT, TEST_CASE_TIMEOUT, + commonEnvironmentVars, } from './constants.js'; -describe(`Metrics E2E tests, manual usage`, () => { +describe('Metrics E2E tests, manual usage', () => { const testStack = new TestStack({ stackNameProps: { stackNamePrefix: RESOURCE_NAME_PREFIX, @@ -191,7 +191,7 @@ describe(`Metrics E2E tests, manual usage`, () => { ? metricStat.Datapoints[0] : {}; expect(singleDataPoint.Sum).toBeGreaterThanOrEqual( - parseInt(expectedMetricValue) * invocations + Number.parseInt(expectedMetricValue) * invocations ); }, TEST_CASE_TIMEOUT diff --git a/packages/metrics/tests/helpers/metricsUtils.ts b/packages/metrics/tests/helpers/metricsUtils.ts index 859c551266..d68afc2793 100644 --- a/packages/metrics/tests/helpers/metricsUtils.ts +++ b/packages/metrics/tests/helpers/metricsUtils.ts @@ -1,16 +1,14 @@ -import promiseRetry from 'promise-retry'; -import { Metrics, MetricUnit } from '../../src/index.js'; -import { ExtraOptions } from '../../src/types/index.js'; +import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; import { - CloudWatchClient, + type CloudWatchClient, + type Dimension, ListMetricsCommand, -} from '@aws-sdk/client-cloudwatch'; -import type { - Dimension, - ListMetricsCommandOutput, + type ListMetricsCommandOutput, } from '@aws-sdk/client-cloudwatch'; import type { Context, Handler } from 'aws-lambda'; -import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; +import promiseRetry from 'promise-retry'; +import { MetricUnit, type Metrics } from '../../src/index.js'; +import type { ExtraOptions } from '../../src/types/index.js'; const getMetrics = async ( cloudWatchClient: CloudWatchClient, diff --git a/packages/metrics/tests/helpers/resources.ts b/packages/metrics/tests/helpers/resources.ts index 128332eb88..9b1b97b81b 100644 --- a/packages/metrics/tests/helpers/resources.ts +++ b/packages/metrics/tests/helpers/resources.ts @@ -1,9 +1,9 @@ import type { TestStack } from '@aws-lambda-powertools/testing-utils'; +import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda'; import type { ExtraTestProps, TestNodejsFunctionProps, } from '@aws-lambda-powertools/testing-utils/types'; -import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda'; import { commonEnvironmentVars } from '../e2e/constants.js'; class MetricsTestNodejsFunction extends TestNodejsFunction { diff --git a/packages/metrics/tests/tsconfig.json b/packages/metrics/tests/tsconfig.json index 5654b3e15f..45ba862a85 100644 --- a/packages/metrics/tests/tsconfig.json +++ b/packages/metrics/tests/tsconfig.json @@ -1,11 +1,8 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "rootDir": "../", - "noEmit": true - }, - "include": [ - "../src/**/*", - "./**/*", - ] -} \ No newline at end of file + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "../", + "noEmit": true + }, + "include": ["../src/**/*", "./**/*"] +} diff --git a/packages/metrics/tests/unit/Metrics.test.ts b/packages/metrics/tests/unit/Metrics.test.ts index 54af8ddfb7..e5532f4769 100644 --- a/packages/metrics/tests/unit/Metrics.test.ts +++ b/packages/metrics/tests/unit/Metrics.test.ts @@ -3,16 +3,10 @@ * * @group unit/metrics/class */ -import context from '@aws-lambda-powertools/testing-utils/context'; import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; -import { MetricResolution, MetricUnit, Metrics } from '../../src/index.js'; +import context from '@aws-lambda-powertools/testing-utils/context'; import type { Context, Handler } from 'aws-lambda'; -import type { - Dimensions, - EmfOutput, - MetricsOptions, - ConfigServiceInterface, -} from '../../src/types/index.js'; +import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js'; import { COLD_START_METRIC, DEFAULT_NAMESPACE, @@ -20,8 +14,14 @@ import { MAX_METRICS_SIZE, MAX_METRIC_VALUES_SIZE, } from '../../src/constants.js'; +import { MetricResolution, MetricUnit, Metrics } from '../../src/index.js'; +import type { + ConfigServiceInterface, + Dimensions, + EmfOutput, + MetricsOptions, +} from '../../src/types/index.js'; import { setupDecoratorLambdaHandler } from '../helpers/metricsUtils.js'; -import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js'; jest.mock('node:console', () => ({ ...jest.requireActual('node:console'), @@ -367,7 +367,9 @@ describe('Class: Metrics', () => { ); } }).not.toThrowError(); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['defaultDimensions']).length).toBe(1); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['dimensions']).length).toBe( MAX_DIMENSION_COUNT - 1 ); @@ -401,7 +403,9 @@ describe('Class: Metrics', () => { ); } }).not.toThrowError(); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['defaultDimensions']).length).toBe(3); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['dimensions']).length).toBe( MAX_DIMENSION_COUNT - 3 ); @@ -470,6 +474,7 @@ describe('Class: Metrics', () => { expect(() => metrics.addDimensions(dimensionsToBeAdded) ).not.toThrowError(); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['dimensions']).length).toBe( MAX_DIMENSION_COUNT ); @@ -487,6 +492,7 @@ describe('Class: Metrics', () => { // Act & Assess metrics.addDimensions(dimensionsToBeAdded); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['dimensions']).length).toBe( MAX_DIMENSION_COUNT ); @@ -692,6 +698,7 @@ describe('Class: Metrics', () => { metrics.addMetric(`${metricName}-${i}`, MetricUnit.Count, i); } }).not.toThrowError(); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['storedMetrics']).length).toEqual( MAX_METRICS_SIZE ); @@ -718,6 +725,7 @@ describe('Class: Metrics', () => { test('it should publish metrics when the array of values reaches the maximum size', () => { // Prepare const metrics: Metrics = new Metrics({ namespace: TEST_NAMESPACE }); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing const consoleSpy = jest.spyOn(metrics['console'], 'log'); const metricName = 'test-metric'; @@ -758,11 +766,13 @@ describe('Class: Metrics', () => { metrics.addMetric(`${metricName}-${i}`, MetricUnit.Count, i); } }).not.toThrowError(); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['storedMetrics']).length).toEqual( MAX_METRICS_SIZE - 1 ); metrics.addMetric('another-metric', MetricUnit.Count, MAX_METRICS_SIZE); expect(publishStoredMetricsSpy).toHaveBeenCalledTimes(0); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['storedMetrics']).length).toEqual( MAX_METRICS_SIZE ); @@ -1262,6 +1272,7 @@ describe('Class: Metrics', () => { const metrics: Metrics = new Metrics({ namespace: TEST_NAMESPACE }); metrics.addMetric('test-metric', MetricUnit.Count, 10); const consoleLogSpy = jest + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing .spyOn(metrics['console'], 'log') .mockImplementation(); const mockData: EmfOutput = { @@ -1638,9 +1649,9 @@ describe('Class: Metrics', () => { 3 ); expect(loggedData.service).toEqual(defaultServiceName); - Object.keys(additionalDimensions).forEach((key) => { + for (const key of Object.keys(additionalDimensions)) { expect(loggedData[key]).toEqual(additionalDimensions[key]); - }); + } expect(loggedData).toEqual({ _aws: { CloudWatchMetrics: [ @@ -2096,6 +2107,7 @@ describe('Class: Metrics', () => { expect(() => metrics.setDefaultDimensions(defaultDimensions) ).not.toThrowError(); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['defaultDimensions']).length).toBe( MAX_DIMENSION_COUNT - 1 ); @@ -2129,6 +2141,7 @@ describe('Class: Metrics', () => { expect(() => metrics.setDefaultDimensions(defaultDimensions) ).not.toThrowError(); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(Object.keys(metrics['defaultDimensions']).length).toBe( MAX_DIMENSION_COUNT - 1 ); @@ -2208,6 +2221,7 @@ describe('Class: Metrics', () => { const metrics: Metrics = new Metrics({ namespace: TEST_NAMESPACE }); // Act & Assess + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing expect(metrics['console']).toEqual(console); }); }); diff --git a/packages/metrics/tests/unit/middleware/middy.test.ts b/packages/metrics/tests/unit/middleware/middy.test.ts index f39d9f8db8..97436531f9 100644 --- a/packages/metrics/tests/unit/middleware/middy.test.ts +++ b/packages/metrics/tests/unit/middleware/middy.test.ts @@ -3,12 +3,12 @@ * * @group unit/metrics/middleware */ -import { Metrics, MetricUnit, MetricResolution } from '../../../src/index.js'; -import { logMetrics } from '../../../src/middleware/middy.js'; -import middy from '@middy/core'; -import { ExtraOptions } from '../../../src/types/index.js'; import { cleanupMiddlewares } from '@aws-lambda-powertools/commons'; import context from '@aws-lambda-powertools/testing-utils/context'; +import middy from '@middy/core'; +import { MetricResolution, MetricUnit, Metrics } from '../../../src/index.js'; +import { logMetrics } from '../../../src/middleware/middy.js'; +import type { ExtraOptions } from '../../../src/types/index.js'; jest.mock('node:console', () => ({ ...jest.requireActual('node:console'), @@ -91,6 +91,7 @@ describe('Middy middleware', () => { serviceName: 'orders', }); const consoleSpy = jest + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing .spyOn(metrics['console'], 'log') .mockImplementation(); // Monkey patch the singleMetric method to return the metrics instance @@ -128,6 +129,7 @@ describe('Middy middleware', () => { serviceName: 'orders', }); const consoleSpy = jest + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing .spyOn(metrics['console'], 'log') .mockImplementation(); // Monkey patch the singleMetric method to return the metrics instance @@ -168,6 +170,7 @@ describe('Middy middleware', () => { namespace: 'serverlessAirline', serviceName: 'orders', }); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing const consoleSpy = jest.spyOn(metrics['console'], 'log'); const handler = middy(async (): Promise => { metrics.addMetric('successfulBooking', MetricUnit.Count, 2); @@ -203,6 +206,7 @@ describe('Middy middleware', () => { namespace: 'serverlessAirline', serviceName: 'orders', }); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing const consoleSpy = jest.spyOn(metrics['console'], 'log'); const metricsOptions: ExtraOptions = { throwOnEmptyMetrics: true, @@ -244,6 +248,7 @@ describe('Middy middleware', () => { namespace: 'serverlessAirline', serviceName: 'orders', }); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing const consoleSpy = jest.spyOn(metrics['console'], 'log'); const handler = middy(async (): Promise => { metrics.addMetric('successfulBooking', MetricUnit.Count, 1); @@ -278,6 +283,7 @@ describe('Middy middleware', () => { namespace: 'serverlessAirline', serviceName: 'orders', }); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing const consoleSpy = jest.spyOn(metrics['console'], 'log'); const handler = middy(async (): Promise => { metrics.addMetric('successfulBooking', MetricUnit.Count, 1); @@ -362,6 +368,7 @@ describe('Middy middleware', () => { serviceName: 'orders', }); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing const consoleSpy = jest.spyOn(metrics['console'], 'log'); const handler = middy((): void => { metrics.addMetric( @@ -405,6 +412,7 @@ describe('Middy middleware', () => { namespace: 'serverlessAirline', serviceName: 'orders', }); + // biome-ignore lint/complexity/useLiteralKeys: This needs to be accessed with literal key for testing const consoleSpy = jest.spyOn(metrics['console'], 'log'); const handler = middy((): void => { metrics.addMetric( diff --git a/packages/metrics/tsconfig.esm.json b/packages/metrics/tsconfig.esm.json index 123291b0cf..82486b64fa 100644 --- a/packages/metrics/tsconfig.esm.json +++ b/packages/metrics/tsconfig.esm.json @@ -6,7 +6,5 @@ "rootDir": "./src", "tsBuildInfoFile": ".tsbuildinfo/esm.json" }, - "include": [ - "./src/**/*" - ] -} \ No newline at end of file + "include": ["./src/**/*"] +} diff --git a/packages/metrics/tsconfig.json b/packages/metrics/tsconfig.json index f216927295..0f0cc593ac 100644 --- a/packages/metrics/tsconfig.json +++ b/packages/metrics/tsconfig.json @@ -1,11 +1,9 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib/cjs", - "rootDir": "./src", - "tsBuildInfoFile": ".tsbuildinfo/cjs.json" - }, - "include": [ - "./src/**/*" - ], -} \ No newline at end of file + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./lib/cjs", + "rootDir": "./src", + "tsBuildInfoFile": ".tsbuildinfo/cjs.json" + }, + "include": ["./src/**/*"] +} diff --git a/packages/metrics/typedoc.json b/packages/metrics/typedoc.json index a81c0d5f1d..ecfe51c09b 100644 --- a/packages/metrics/typedoc.json +++ b/packages/metrics/typedoc.json @@ -1,10 +1,5 @@ { - "extends": [ - "../../typedoc.base.json" - ], - "entryPoints": [ - "./src/index.ts", - "./src/types/index.ts" - ], + "extends": ["../../typedoc.base.json"], + "entryPoints": ["./src/index.ts", "./src/types/index.ts"], "readme": "README.md" -} \ No newline at end of file +}