Skip to content

Commit 86c2cae

Browse files
fix: CLI CDK context parameter (#61)
* fix: CLI CDK context parameter * Fix tests * Fix tests * Improve log
1 parent dc99c79 commit 86c2cae

File tree

8 files changed

+32
-9
lines changed

8 files changed

+32
-9
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
"type": "node",
2525
"cwd": "${workspaceRoot}/test/cdk-basic"
2626
},
27+
{
28+
"name": "LLDebugger - CDK basic - monorepo",
29+
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
30+
"args": [
31+
"../src/lldebugger.ts",
32+
"-c environment=test",
33+
"--subfolder=cdk-basic"
34+
],
35+
// "args": ["../src/lldebugger.ts", "-w"],
36+
"request": "launch",
37+
"skipFiles": ["<node_internals>/**"],
38+
"console": "integratedTerminal",
39+
"type": "node",
40+
"cwd": "${workspaceRoot}/test"
41+
},
2742
{
2843
"name": "LLDebugger - CDK ESM",
2944
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",

src/frameworks/cdkFramework.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ export class CdkFramework implements IFramework {
556556
(acc: Record<string, string>, arg: string) => {
557557
const [key, value] = arg.split('=');
558558
if (key && value) {
559-
acc[key] = value;
559+
acc[key.trim()] = value.trim();
560560
}
561561
return acc;
562562
},

src/frameworks/cdkFrameworkWorker.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ parentPort.on('message', async (data) => {
1111
// this is global variable to store the data from the CDK code once it is executed
1212
global.lambdas = [];
1313

14-
Logger.verbose(`[Worker ${workerData.workerId}] Received message`, data);
14+
Logger.verbose(`[Worker] Received message`, data);
1515

1616
// execute code to get the data into global.lambdas
1717
await import(data.compileOutput);

test/cdk-basic.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('cdk-basic', async () => {
2424

2525
beforeAll(async () => {
2626
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
27-
lldProcess = await startDebugger(folder, ['-c=environment=test']);
27+
lldProcess = await startDebugger(folder, ['-c environment=test']);
2828
}
2929
});
3030

@@ -139,7 +139,7 @@ describe('cdk-basic', async () => {
139139

140140
test('remove infra', async () => {
141141
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
142-
await removeInfra(lldProcess, folder);
142+
await removeInfra(lldProcess, folder, ['-c environment=test']);
143143
const lambdaName = await getFunctionName(
144144
folder,
145145
'FunctionNameTestTsCommonJs',

test/cdk-basic/bin/cdk-basic.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { CdkbasicStack2 } from '../lib/subfolder/cdk-basic-stack2';
66

77
const app = new cdk.App();
88

9-
const environment = 'test';
9+
const environment = app.node.tryGetContext('environment');
10+
11+
if (!environment) {
12+
throw new Error('Environment is not set in the context');
13+
}
1014

1115
new CdkbasicStack(app, 'CdkbasicStack', {
1216
stackName: `${environment}-lld-cdk-basic`,

test/cdk-esm.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('cdk-esm', async () => {
2424

2525
beforeAll(async () => {
2626
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
27-
lldProcess = await startDebugger(folder, ['-c=environment=test']);
27+
lldProcess = await startDebugger(folder, ['-c environment=test']);
2828
}
2929
});
3030

@@ -139,7 +139,7 @@ describe('cdk-esm', async () => {
139139

140140
test('remove infra', async () => {
141141
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
142-
await removeInfra(lldProcess, folder);
142+
await removeInfra(lldProcess, folder, ['-c environment=test']);
143143
const lambdaName = await getFunctionName(
144144
folder,
145145
'FunctionNameTestTsCommonJs',

test/cdk-esm/bin/cdk-esm.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { CdkEsmStack2 } from '../lib/subfolder/cdk-esm-stack2';
88

99
const app = new cdk.App();
1010

11-
const environment = 'test';
11+
const environment = app.node.tryGetContext('environment');
12+
13+
if (!environment) {
14+
throw new Error('Environment is not set in the context');
15+
}
1216

1317
new CdkEsmStack(app, 'CdkEsmStack', {
1418
stackName: `${environment}-lld-cdk-esm`,

test/terraform-basic.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('terraform-basic', async () => {
2222

2323
beforeAll(async () => {
2424
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
25-
lldProcess = await startDebugger(folder, ['-c=environment=test']);
25+
lldProcess = await startDebugger(folder);
2626
}
2727
});
2828

0 commit comments

Comments
 (0)