Skip to content

Commit d4bdf1b

Browse files
committed
chore(logger): make E2E works for all runtimes
1 parent 18228d5 commit d4bdf1b

File tree

6 files changed

+191
-18
lines changed

6 files changed

+191
-18
lines changed

Diff for: packages/logger/package-lock.json

+133
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/logger/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"commit": "commit",
1414
"test": "npm run test:unit",
1515
"test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose",
16-
"test:e2e": "jest --group=e2e",
16+
"test:e2e:nodejs12x": "RUNTIME=nodejs12x jest --group=e2e/logger",
17+
"test:e2e:nodejs14x": "RUNTIME=nodejs14x jest --group=e2e/logger",
18+
"test:e2e": "concurrently \"npm:test:e2e:nodejs12x\" \"npm:test:e2e:nodejs14x\"",
1719
"watch": "jest --watch",
1820
"build": "tsc",
1921
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
@@ -43,6 +45,7 @@
4345
"types": "./lib/index.d.ts",
4446
"typedocMain": "src/index.ts",
4547
"devDependencies": {
48+
"@aws-cdk/aws-lambda": "^1.137.0",
4649
"@aws-cdk/aws-lambda-nodejs": "^1.137.0",
4750
"@aws-cdk/core": "^1.137.0",
4851
"@middy/core": "^2.5.6",
@@ -55,6 +58,7 @@
5558
"@typescript-eslint/parser": "^5.4.0",
5659
"aws-cdk": "^1.137.0",
5760
"aws-sdk": "^2.1048.0",
61+
"concurrently": "^7.0.0",
5862
"eslint": "^8.3.0",
5963
"eslint-import-resolver-node": "^0.3.6",
6064
"eslint-import-resolver-typescript": "^2.5.0",

Diff for: packages/logger/tests/e2e/basicFeatures.middy.test.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@
1010
import path from 'path';
1111
import { randomUUID } from 'crypto';
1212
import { App, Stack } from '@aws-cdk/core';
13-
import { createStackWithLambdaFunction, deployStack, destroyStack, invokeFunction } from '../helpers/e2eUtils';
13+
import { createStackWithLambdaFunction, deployStack, destroyStack, generateUniqueName, invokeFunction, isValidRuntimeKey } from '../helpers/e2eUtils';
1414
import { InvocationLogs } from '../helpers/InvocationLogs';
1515

16+
const runtime: string = process.env.RUNTIME || 'nodejs14x';
17+
18+
if (!isValidRuntimeKey(runtime)) {
19+
throw new Error(`Invalid runtime key value: ${runtime}`);
20+
}
21+
1622
const LEVEL = InvocationLogs.LEVEL;
1723
const TEST_CASE_TIMEOUT = 20000; // 20 seconds
1824
const SETUP_TIMEOUT = 200000; // 200 seconds
1925
const TEARDOWN_TIMEOUT = 200000;
2026
const STACK_OUTPUT_LOG_GROUP = 'LogGroupName';
2127

2228
const uuid = randomUUID();
23-
const stackName = `LoggerE2EBasicFeatureMiddyStack-${uuid}`;
24-
const functionName = `loggerE2EBasicFeaturesMiddy-${uuid}`;
29+
const stackName = generateUniqueName(uuid, runtime, 'BasicFeatures-Middy');
30+
const functionName = `LoggerE2E-${runtime}-BasicFeatures-Middy-${uuid}`.substring(0, 64);
2531
const lambdaFunctionCodeFile = 'basicFeatures.middy.test.FunctionCode.ts';
2632

2733
// Text to be used by Logger in the Lambda function
@@ -34,12 +40,12 @@ const ERROR_MSG = `error-${uuid}`;
3440
const integTestApp = new App();
3541
let logGroupName: string; // We do not know it until deployment
3642
let stack: Stack;
37-
describe('logger E2E tests basic functionalities (middy)', () => {
43+
44+
describe(`logger E2E tests basic functionalities (middy) for runtime: ${runtime}`, () => {
3845

3946
let invocationLogs: InvocationLogs[];
4047

4148
beforeAll(async () => {
42-
4349
// Create and deploy a stack with AWS CDK
4450
stack = createStackWithLambdaFunction({
4551
app: integTestApp,
@@ -58,7 +64,8 @@ describe('logger E2E tests basic functionalities (middy)', () => {
5864
SINGLE_LOG_ITEM_VALUE,
5965
ERROR_MSG,
6066
},
61-
logGroupOutputKey: STACK_OUTPUT_LOG_GROUP
67+
logGroupOutputKey: STACK_OUTPUT_LOG_GROUP,
68+
runtime: runtime,
6269
});
6370
const stackArtifact = integTestApp.synth().getStackByName(stack.stackName);
6471
const outputs = await deployStack(stackArtifact);

Diff for: packages/logger/tests/e2e/childLogger.manual.test.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@
1010
import path from 'path';
1111
import { randomUUID } from 'crypto';
1212
import { App, Stack } from '@aws-cdk/core';
13-
import { createStackWithLambdaFunction, deployStack, destroyStack, invokeFunction } from '../helpers/e2eUtils';
13+
import { createStackWithLambdaFunction, deployStack, destroyStack, generateUniqueName, invokeFunction, isValidRuntimeKey } from '../helpers/e2eUtils';
1414
import { InvocationLogs } from '../helpers/InvocationLogs';
1515

16+
const runtime: string = process.env.RUNTIME || 'nodejs14x';
17+
18+
if (!isValidRuntimeKey(runtime)) {
19+
throw new Error(`Invalid runtime key value: ${runtime}`);
20+
}
21+
1622
const LEVEL = InvocationLogs.LEVEL;
1723
const TEST_CASE_TIMEOUT = 20000; // 20 seconds
1824
const SETUP_TIMEOUT = 200000; // 200 seconds
1925
const TEARDOWN_TIMEOUT = 200000;
2026
const STACK_OUTPUT_LOG_GROUP = 'LogGroupName';
2127

2228
const uuid = randomUUID();
23-
const stackName = `LoggerE2EChildLoggerManualStack-${uuid}`;
24-
const functionName = `LoggerE2EChildLoggerManual-${uuid}`;
29+
const stackName = generateUniqueName(uuid, runtime, 'ChildLogger-Manual');
30+
const functionName = generateUniqueName(uuid, runtime, 'ChildLogger-Manual');
2531
const lambdaFunctionCodeFile = 'childLogger.manual.test.FunctionCode.ts';
2632

2733
// Parameters to be used by Logger in the Lambda function
@@ -34,7 +40,7 @@ const CHILD_LOG_LEVEL = LEVEL.ERROR.toString();
3440
const integTestApp = new App();
3541
let logGroupName: string; // We do not know it until deployment
3642
let stack: Stack;
37-
describe('logger E2E tests child logger functionalities (manual)', () => {
43+
describe(`logger E2E tests child logger functionalities (manual) for runtime: ${runtime}`, () => {
3844

3945
let invocationLogs: InvocationLogs[];
4046

@@ -58,7 +64,8 @@ describe('logger E2E tests child logger functionalities (manual)', () => {
5864
CHILD_LOG_MSG,
5965
CHILD_LOG_LEVEL,
6066
},
61-
logGroupOutputKey: STACK_OUTPUT_LOG_GROUP
67+
logGroupOutputKey: STACK_OUTPUT_LOG_GROUP,
68+
runtime: runtime,
6269
});
6370
const stackArtifact = integTestApp.synth().getStackByName(stack.stackName);
6471
const outputs = await deployStack(stackArtifact);

Diff for: packages/logger/tests/e2e/sampleRate.decorator.test.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010
import path from 'path';
1111
import { randomUUID } from 'crypto';
1212
import { App, Stack } from '@aws-cdk/core';
13-
import { createStackWithLambdaFunction, deployStack, destroyStack, invokeFunction } from '../helpers/e2eUtils';
13+
import { createStackWithLambdaFunction, deployStack, destroyStack, generateUniqueName, invokeFunction, isValidRuntimeKey } from '../helpers/e2eUtils';
1414
import { InvocationLogs } from '../helpers/InvocationLogs';
1515

16-
const LEVEL = InvocationLogs.LEVEL;
16+
const runtime: string = process.env.RUNTIME || 'nodejs14x';
17+
18+
if (!isValidRuntimeKey(runtime)) {
19+
throw new Error(`Invalid runtime key value: ${runtime}`);
20+
}
1721

22+
const LEVEL = InvocationLogs.LEVEL;
1823
const TEST_CASE_TIMEOUT = 30000; // 30 seconds
1924
const SETUP_TIMEOUT = 200000; // 200 seconds
2025
const TEARDOWN_TIMEOUT = 200000;
2126
const STACK_OUTPUT_LOG_GROUP = 'LogGroupName';
2227

2328
const uuid = randomUUID();
24-
const stackName = `LoggerE2ESampleRateDecoratorStack-${uuid}`;
25-
const functionName = `LoggerE2EampleRateDecorator-${uuid}`;
29+
const stackName = generateUniqueName(uuid, runtime, 'SampleRate-Decorator');
30+
const functionName = generateUniqueName(uuid, runtime, 'SampleRate-Decorator');
2631
const lambdaFunctionCodeFile = 'sampleRate.decorator.test.FunctionCode.ts';
2732

2833
// Parameters to be used by Logger in the Lambda function
@@ -32,7 +37,7 @@ const LOG_LEVEL = LEVEL.ERROR.toString();
3237
const integTestApp = new App();
3338
let logGroupName: string; // We do not know it until deployment
3439
let stack: Stack;
35-
describe('logger E2E tests sample rate and injectLambdaContext()', () => {
40+
describe(`logger E2E tests sample rate and injectLambdaContext() for runtime: ${runtime}`, () => {
3641

3742
let invocationLogs: InvocationLogs[];
3843

@@ -53,7 +58,8 @@ describe('logger E2E tests sample rate and injectLambdaContext()', () => {
5358
LOG_MSG,
5459
SAMPLE_RATE,
5560
},
56-
logGroupOutputKey: STACK_OUTPUT_LOG_GROUP
61+
logGroupOutputKey: STACK_OUTPUT_LOG_GROUP,
62+
runtime: runtime,
5763
});
5864
const stackArtifact = integTestApp.synth().getStackByName(stack.stackName);
5965
const outputs = await deployStack(stackArtifact);

0 commit comments

Comments
 (0)