From 266301e36b3349d1e5dc9bd3f95cd45ea27b264c Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 13:12:42 +0200 Subject: [PATCH 1/3] chore(maintenance): add biome.js --- biome.json | 26 ++++++++ package-lock.json | 156 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 183 insertions(+) create mode 100644 biome.json diff --git a/biome.json b/biome.json new file mode 100644 index 0000000000..19d23a030d --- /dev/null +++ b/biome.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2, + "lineEnding": "lf" + }, + "javascript": { + "formatter": { + "semicolons": "always", + "bracketSpacing": true, + "quoteStyle": "single", + "trailingComma": "es5" + } + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ea890dc6e3..80d5733127 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "examples/app" ], "devDependencies": { + "@biomejs/biome": "^1.8.3", "@types/aws-lambda": "^8.10.141", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", @@ -1848,6 +1849,161 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@biomejs/biome": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.8.3.tgz", + "integrity": "sha512-/uUV3MV+vyAczO+vKrPdOW0Iaet7UnJMU4bNMinggGJTAnBPjCoLEYcyYtYHNnUNYlv4xZMH6hVIQCAozq8d5w==", + "dev": true, + "hasInstallScript": true, + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.21.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.8.3", + "@biomejs/cli-darwin-x64": "1.8.3", + "@biomejs/cli-linux-arm64": "1.8.3", + "@biomejs/cli-linux-arm64-musl": "1.8.3", + "@biomejs/cli-linux-x64": "1.8.3", + "@biomejs/cli-linux-x64-musl": "1.8.3", + "@biomejs/cli-win32-arm64": "1.8.3", + "@biomejs/cli-win32-x64": "1.8.3" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.8.3.tgz", + "integrity": "sha512-9DYOjclFpKrH/m1Oz75SSExR8VKvNSSsLnVIqdnKexj6NwmiMlKk94Wa1kZEdv6MCOHGHgyyoV57Cw8WzL5n3A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.8.3.tgz", + "integrity": "sha512-UeW44L/AtbmOF7KXLCoM+9PSgPo0IDcyEUfIoOXYeANaNXXf9mLUwV1GeF2OWjyic5zj6CnAJ9uzk2LT3v/wAw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.8.3.tgz", + "integrity": "sha512-fed2ji8s+I/m8upWpTJGanqiJ0rnlHOK3DdxsyVLZQ8ClY6qLuPc9uehCREBifRJLl/iJyQpHIRufLDeotsPtw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.8.3.tgz", + "integrity": "sha512-9yjUfOFN7wrYsXt/T/gEWfvVxKlnh3yBpnScw98IF+oOeCYb5/b/+K7YNqKROV2i1DlMjg9g/EcN9wvj+NkMuQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.8.3.tgz", + "integrity": "sha512-I8G2QmuE1teISyT8ie1HXsjFRz9L1m5n83U1O6m30Kw+kPMPSKjag6QGUn+sXT8V+XWIZxFFBoTDEDZW2KPDDw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.8.3.tgz", + "integrity": "sha512-UHrGJX7PrKMKzPGoEsooKC9jXJMa28TUSMjcIlbDnIO4EAavCoVmNQaIuUSH0Ls2mpGMwUIf+aZJv657zfWWjA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.8.3.tgz", + "integrity": "sha512-J+Hu9WvrBevfy06eU1Na0lpc7uR9tibm9maHynLIoAjLZpQU3IW+OKHUtyL8p6/3pT2Ju5t5emReeIS2SAxhkQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.8.3.tgz", + "integrity": "sha512-/PJ59vA1pnQeKahemaQf4Nyj7IKUvGQSc3Ze1uIGi+Wvr1xF7rGobSrAAG01T/gUDG21vkDsZYM03NAmPiVkqg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", diff --git a/package.json b/package.json index 66fcd8ef7d..4efd18859e 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ }, "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme", "devDependencies": { + "@biomejs/biome": "^1.8.3", "@types/aws-lambda": "^8.10.141", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", From 0ed3e1c55fb81bf175a5129cfab99c4109861dfb Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 15:52:41 +0200 Subject: [PATCH 2/3] chore(maintenance): add biome to project --- biome.json | 15 +++++++++++++-- examples/app/cdk/example-stack.ts | 4 ++-- .../app/functions/commons/helpers/get-item.ts | 4 ++-- .../app/functions/commons/helpers/put-item.ts | 6 +++--- .../app/functions/commons/helpers/scan-items.ts | 4 ++-- examples/app/package.json | 10 +++------- package.json | 4 ++-- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/biome.json b/biome.json index 19d23a030d..46c5a0c5d5 100644 --- a/biome.json +++ b/biome.json @@ -13,14 +13,25 @@ "enabled": true, "indentStyle": "space", "indentWidth": 2, - "lineEnding": "lf" + "lineEnding": "lf", + "lineWidth": 80 }, "javascript": { "formatter": { "semicolons": "always", "bracketSpacing": true, "quoteStyle": "single", - "trailingComma": "es5" + "trailingCommas": "es5" } + }, + "files": { + "ignore": [ + "node_modules", + "coverage", + "lib", + "cdk.out", + "site", + ".aws-sam" + ] } } \ No newline at end of file diff --git a/examples/app/cdk/example-stack.ts b/examples/app/cdk/example-stack.ts index b5e7f66284..067ef6752f 100644 --- a/examples/app/cdk/example-stack.ts +++ b/examples/app/cdk/example-stack.ts @@ -1,4 +1,4 @@ -import { RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib'; +import { RemovalPolicy, Stack, type StackProps } from 'aws-cdk-lib'; import { LambdaIntegration, RestApi } from 'aws-cdk-lib/aws-apigateway'; import { AttributeType, @@ -18,7 +18,7 @@ import { DynamoEventSource } from 'aws-cdk-lib/aws-lambda-event-sources'; import { OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs'; import { Queue } from 'aws-cdk-lib/aws-sqs'; import { StringParameter } from 'aws-cdk-lib/aws-ssm'; -import { Construct } from 'constructs'; +import type { Construct } from 'constructs'; import { FunctionWithLogGroup } from './function-with-logstream-construct.js'; export class PowertoolsExampleStack extends Stack { diff --git a/examples/app/functions/commons/helpers/get-item.ts b/examples/app/functions/commons/helpers/get-item.ts index 3ce1030ea7..165b01f0d0 100644 --- a/examples/app/functions/commons/helpers/get-item.ts +++ b/examples/app/functions/commons/helpers/get-item.ts @@ -1,7 +1,7 @@ +import { GetCommand, type GetCommandOutput } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { GetCommand, type GetCommandOutput } from '@aws-sdk/lib-dynamodb'; /** * Fetch an item from the DynamoDB table. @@ -22,7 +22,7 @@ const getItemDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/functions/commons/helpers/put-item.ts b/examples/app/functions/commons/helpers/put-item.ts index a978e0382c..853756899d 100644 --- a/examples/app/functions/commons/helpers/put-item.ts +++ b/examples/app/functions/commons/helpers/put-item.ts @@ -1,8 +1,8 @@ +import { randomUUID } from 'node:crypto'; +import { PutCommand } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { PutCommand } from '@aws-sdk/lib-dynamodb'; -import { randomUUID } from 'node:crypto'; /** * Put an item in the DynamoDB table. @@ -28,7 +28,7 @@ const putItemInDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/functions/commons/helpers/scan-items.ts b/examples/app/functions/commons/helpers/scan-items.ts index 858b752c1d..d528085f28 100644 --- a/examples/app/functions/commons/helpers/scan-items.ts +++ b/examples/app/functions/commons/helpers/scan-items.ts @@ -1,7 +1,7 @@ +import { ScanCommand, type ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { ScanCommand, type ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; /** * Scan the DynamoDB table and return all items. @@ -19,7 +19,7 @@ const scanItemsDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/package.json b/examples/app/package.json index 30b84d438e..8f6c790d63 100644 --- a/examples/app/package.json +++ b/examples/app/package.json @@ -11,16 +11,12 @@ "scripts": { "build": "echo 'Not applicable, run `npx cdk synth` instead to build the stack'", "test": "npm run test:unit", - "lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .", - "lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .", + "lint": "biome lint .", + "lint:fix": "biome check --write .", "test:unit": "export POWERTOOLS_DEV=true && jest --silent", "test:e2e": "echo 'To be implemented ...'", "cdk": "cdk" }, - "lint-staged": { - "*.ts": "npm run lint-fix", - "*.js": "npm run lint-fix" - }, "type": "module", "imports": { "#types": "./functions/commons/types.js", @@ -64,4 +60,4 @@ "ts-node": "^10.9.2", "typescript": "^5.4.5" } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 4efd18859e..c1f422af13 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "typescript": "^5.4.5" }, "lint-staged": { - "*.{js,ts}": "eslint --fix", + "*.{js,ts}": "biome check --write", "*.md": "markdownlint-cli2 --fix" }, "engines": { @@ -89,4 +89,4 @@ "tar": "6.2.1" } } -} +} \ No newline at end of file From 1cb7ed26f56eb96f1dd606febac9bd8f568fe66c Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 16:28:46 +0200 Subject: [PATCH 3/3] chore(maintenance): migrate layers to biome --- layers/bin/layers.ts | 2 +- layers/cdk.json | 9 +---- layers/package.json | 4 +- layers/src/canary-stack.ts | 14 +++---- layers/src/layer-publisher-stack.ts | 12 +++--- .../layerPublisher.class.test.functionCode.ts | 20 +++++----- layers/tests/e2e/layerPublisher.test.ts | 38 +++++++++++-------- layers/tests/tsconfig.json | 18 ++++----- layers/tsconfig.json | 19 ++++------ 9 files changed, 65 insertions(+), 71 deletions(-) diff --git a/layers/bin/layers.ts b/layers/bin/layers.ts index be4605b3e3..e4c5148311 100644 --- a/layers/bin/layers.ts +++ b/layers/bin/layers.ts @@ -1,8 +1,8 @@ #!/usr/bin/env node import 'source-map-support/register'; import { App } from 'aws-cdk-lib'; -import { LayerPublisherStack } from '../src/layer-publisher-stack'; import { CanaryStack } from 'layers/src/canary-stack'; +import { LayerPublisherStack } from '../src/layer-publisher-stack'; const SSM_PARAM_LAYER_ARN = '/layers/powertools-layer-arn'; diff --git a/layers/cdk.json b/layers/cdk.json index 4ca6aac30e..d01ddd44bc 100644 --- a/layers/cdk.json +++ b/layers/cdk.json @@ -1,9 +1,7 @@ { "app": "npx ts-node --prefer-ts-exts bin/layers.ts", "watch": { - "include": [ - "**" - ], + "include": ["**"], "exclude": [ "README.md", "cdk*.json", @@ -24,9 +22,6 @@ "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, - "@aws-cdk/core:target-partitions": [ - "aws", - "aws-cn" - ] + "@aws-cdk/core:target-partitions": ["aws", "aws-cn"] } } diff --git a/layers/package.json b/layers/package.json index 748686d6da..1a76536d03 100644 --- a/layers/package.json +++ b/layers/package.json @@ -12,8 +12,8 @@ "jest": "jest --detectOpenHandles", "cdk": "cdk", "package": "echo 'Not applicable'", - "lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .", - "lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .", + "lint": "biome lint .", + "lint:fix": "biome check --write .", "test:unit": "jest --group=unit", "test:e2e": "jest --group=e2e", "createLayerFolder": "cdk synth --context BuildFromLocal=true" diff --git a/layers/src/canary-stack.ts b/layers/src/canary-stack.ts index 645c9c40c9..9ee3a4031b 100644 --- a/layers/src/canary-stack.ts +++ b/layers/src/canary-stack.ts @@ -1,13 +1,13 @@ -import { CustomResource, Duration, Stack, StackProps } from 'aws-cdk-lib'; -import { Construct } from 'constructs'; -import { LayerVersion, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda'; -import { RetentionDays } from 'aws-cdk-lib/aws-logs'; import { randomUUID } from 'node:crypto'; -import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam'; -import { Provider } from 'aws-cdk-lib/custom-resources'; -import { StringParameter } from 'aws-cdk-lib/aws-ssm'; import path from 'node:path'; +import { CustomResource, Duration, Stack, type StackProps } from 'aws-cdk-lib'; +import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam'; +import { LayerVersion, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda'; import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; +import { RetentionDays } from 'aws-cdk-lib/aws-logs'; +import { StringParameter } from 'aws-cdk-lib/aws-ssm'; +import { Provider } from 'aws-cdk-lib/custom-resources'; +import type { Construct } from 'constructs'; export interface CanaryStackProps extends StackProps { readonly layerName: string; diff --git a/layers/src/layer-publisher-stack.ts b/layers/src/layer-publisher-stack.ts index 71da06737c..74ea60cc67 100644 --- a/layers/src/layer-publisher-stack.ts +++ b/layers/src/layer-publisher-stack.ts @@ -1,4 +1,7 @@ -import { CfnOutput, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib'; +import { execSync } from 'node:child_process'; +import { randomUUID } from 'node:crypto'; +import { join, resolve, sep } from 'node:path'; +import { CfnOutput, RemovalPolicy, Stack, type StackProps } from 'aws-cdk-lib'; import { CfnLayerVersionPermission, Code, @@ -6,10 +9,7 @@ import { Runtime, } from 'aws-cdk-lib/aws-lambda'; import { StringParameter } from 'aws-cdk-lib/aws-ssm'; -import { Construct } from 'constructs'; -import { execSync } from 'node:child_process'; -import { randomUUID } from 'node:crypto'; -import { join, resolve, sep } from 'node:path'; +import type { Construct } from 'constructs'; export interface LayerPublisherStackProps extends StackProps { readonly layerName?: string; @@ -217,7 +217,7 @@ export class LayerPublisherStack extends Stack { new CfnOutput(this, 'LatestLayerArn', { value: this.lambdaLayerVersion.layerVersionArn, - exportName: props?.layerName ?? `LambdaPowerToolsForTypeScriptLayerARN`, + exportName: props?.layerName ?? 'LambdaPowerToolsForTypeScriptLayerARN', }); } } diff --git a/layers/tests/e2e/layerPublisher.class.test.functionCode.ts b/layers/tests/e2e/layerPublisher.class.test.functionCode.ts index b95eeafea9..a58bcbde9d 100644 --- a/layers/tests/e2e/layerPublisher.class.test.functionCode.ts +++ b/layers/tests/e2e/layerPublisher.class.test.functionCode.ts @@ -1,18 +1,18 @@ -import { join } from 'node:path'; import { readFile } from 'node:fs/promises'; +import { join } from 'node:path'; +import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch'; +import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; import { Logger } from '@aws-lambda-powertools/logger'; import { Metrics } from '@aws-lambda-powertools/metrics'; -import { Tracer } from '@aws-lambda-powertools/tracer'; -import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; -import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; -import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch'; -import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm'; -import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets'; import { AppConfigProvider } from '@aws-lambda-powertools/parameters/appconfig'; import { DynamoDBProvider } from '@aws-lambda-powertools/parameters/dynamodb'; -import { SSMClient } from '@aws-sdk/client-ssm'; -import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager'; +import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets'; +import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm'; +import { Tracer } from '@aws-lambda-powertools/tracer'; import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata'; +import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; +import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager'; +import { SSMClient } from '@aws-sdk/client-ssm'; const logger = new Logger({ logLevel: 'DEBUG', @@ -91,7 +91,7 @@ export const handler = async (): Promise => { 'batch', ]) { const moduleVersion = await getVersionFromModule(moduleName); - if (moduleVersion != expectedVersion) { + if (moduleVersion !== expectedVersion) { throw new Error( `Package version mismatch (${moduleName}): ${moduleVersion} != ${expectedVersion}` ); diff --git a/layers/tests/e2e/layerPublisher.test.ts b/layers/tests/e2e/layerPublisher.test.ts index a00f2cb742..56d7441397 100644 --- a/layers/tests/e2e/layerPublisher.test.ts +++ b/layers/tests/e2e/layerPublisher.test.ts @@ -3,23 +3,23 @@ * * @group e2e/layers/all */ -import { App } from 'aws-cdk-lib'; -import { LayerVersion } from 'aws-cdk-lib/aws-lambda'; -import { LayerPublisherStack } from '../../src/layer-publisher-stack'; +import { join } from 'node:path'; import { - TestStack, TestInvocationLogs, - invokeFunctionOnce, + TestStack, generateTestUniqueName, + invokeFunctionOnce, } from '@aws-lambda-powertools/testing-utils'; import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda'; +import { App } from 'aws-cdk-lib'; +import { LayerVersion } from 'aws-cdk-lib/aws-lambda'; +import packageJson from '../../package.json'; +import { LayerPublisherStack } from '../../src/layer-publisher-stack'; import { RESOURCE_NAME_PREFIX, SETUP_TIMEOUT, TEARDOWN_TIMEOUT, } from './constants'; -import { join } from 'node:path'; -import packageJson from '../../package.json'; jest.spyOn(console, 'log').mockImplementation(); @@ -39,7 +39,7 @@ function assertLogs( * * The lambda function is invoked once and the logs are collected. The goal of the test is to verify that the layer creation and usage works as expected. */ -describe(`Layers E2E tests`, () => { +describe('Layers E2E tests', () => { const testStack = new TestStack({ stackNameProps: { stackNamePrefix: RESOURCE_NAME_PREFIX, @@ -96,7 +96,7 @@ describe(`Layers E2E tests`, () => { ); // Add a lambda function for each output format to the test stack - cases.forEach((outputFormat) => { + for (const outputFormat of cases) { new TestNodejsFunction( testStack, { @@ -120,7 +120,7 @@ describe(`Layers E2E tests`, () => { ...(outputFormat === 'ESM' && { outputFormat: 'ESM' }), } ); - }); + } // Deploy the test stack await testStack.deploy(); @@ -141,20 +141,19 @@ describe(`Layers E2E tests`, () => { describe.each(cases)( 'utilities tests for %s output format', (outputFormat) => { - let invocationLogs: TestInvocationLogs; - beforeAll(() => { + it('should have no errors in the logs, which indicates the pacakges version matches the expected one', () => { const maybeInvocationLogs = invocationLogsMap.get(outputFormat); assertLogs(maybeInvocationLogs); - invocationLogs = maybeInvocationLogs; - }); - - it('should have no errors in the logs, which indicates the pacakges version matches the expected one', () => { + const invocationLogs = maybeInvocationLogs; const logs = invocationLogs.getFunctionLogs('ERROR'); expect(logs.length).toBe(0); }); it('should have one warning related to missing Metrics namespace', () => { + const maybeInvocationLogs = invocationLogsMap.get(outputFormat); + assertLogs(maybeInvocationLogs); + const invocationLogs = maybeInvocationLogs; const logs = invocationLogs.getFunctionLogs('WARN'); expect(logs.length).toBe(1); @@ -162,7 +161,11 @@ describe(`Layers E2E tests`, () => { }); it('should have one info log related to coldstart metric', () => { + const maybeInvocationLogs = invocationLogsMap.get(outputFormat); + assertLogs(maybeInvocationLogs); + const invocationLogs = maybeInvocationLogs; const logs = invocationLogs.getFunctionLogs(); + const emfLogEntry = logs.find((log) => log.match( /{"_aws":{"Timestamp":\d+,"CloudWatchMetrics":\[\{"Namespace":"\S+","Dimensions":\[\["service"\]\],"Metrics":\[\{"Name":"ColdStart","Unit":"Count"\}\]\}\]},"service":"\S+","ColdStart":1}/ @@ -173,6 +176,9 @@ describe(`Layers E2E tests`, () => { }); it('should have one debug log with tracer subsegment info', () => { + const maybeInvocationLogs = invocationLogsMap.get(outputFormat); + assertLogs(maybeInvocationLogs); + const invocationLogs = maybeInvocationLogs; const logs = invocationLogs.getFunctionLogs('DEBUG'); expect(logs.length).toBe(1); diff --git a/layers/tests/tsconfig.json b/layers/tests/tsconfig.json index a07fdb8a65..0bbd7e9af9 100644 --- a/layers/tests/tsconfig.json +++ b/layers/tests/tsconfig.json @@ -1,12 +1,8 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "rootDir": "../", - "noEmit": true - }, - "include": [ - "../src/**/*", - "../package.json", - "./**/*", - ] -} \ No newline at end of file + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "../", + "noEmit": true + }, + "include": ["../src/**/*", "../package.json", "./**/*"] +} diff --git a/layers/tsconfig.json b/layers/tsconfig.json index 4acbde11be..5194193adc 100644 --- a/layers/tsconfig.json +++ b/layers/tsconfig.json @@ -1,12 +1,9 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "outDir": "./lib", - "rootDir": "./", - "resolveJsonModule": true - }, - "include": [ - "./src/**/*", - "./bin/**/*" - ], -} \ No newline at end of file + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "./lib", + "rootDir": "./", + "resolveJsonModule": true + }, + "include": ["./src/**/*", "./bin/**/*"] +}