Skip to content

Commit

Permalink
fix: CLI CDK context parameter (#61)
Browse files Browse the repository at this point in the history
* fix: CLI CDK context parameter

* Fix tests

* Fix tests

* Improve log
  • Loading branch information
ServerlessLife authored Oct 1, 2024
1 parent dc99c79 commit 86c2cae
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 9 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
"type": "node",
"cwd": "${workspaceRoot}/test/cdk-basic"
},
{
"name": "LLDebugger - CDK basic - monorepo",
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
"args": [
"../src/lldebugger.ts",
"-c environment=test",
"--subfolder=cdk-basic"
],
// "args": ["../src/lldebugger.ts", "-w"],
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal",
"type": "node",
"cwd": "${workspaceRoot}/test"
},
{
"name": "LLDebugger - CDK ESM",
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/cdkFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ export class CdkFramework implements IFramework {
(acc: Record<string, string>, arg: string) => {
const [key, value] = arg.split('=');
if (key && value) {
acc[key] = value;
acc[key.trim()] = value.trim();
}
return acc;
},
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/cdkFrameworkWorker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ parentPort.on('message', async (data) => {
// this is global variable to store the data from the CDK code once it is executed
global.lambdas = [];

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

// execute code to get the data into global.lambdas
await import(data.compileOutput);
Expand Down
4 changes: 2 additions & 2 deletions test/cdk-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('cdk-basic', async () => {

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

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

test('remove infra', async () => {
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
await removeInfra(lldProcess, folder);
await removeInfra(lldProcess, folder, ['-c environment=test']);
const lambdaName = await getFunctionName(
folder,
'FunctionNameTestTsCommonJs',
Expand Down
6 changes: 5 additions & 1 deletion test/cdk-basic/bin/cdk-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { CdkbasicStack2 } from '../lib/subfolder/cdk-basic-stack2';

const app = new cdk.App();

const environment = 'test';
const environment = app.node.tryGetContext('environment');

if (!environment) {
throw new Error('Environment is not set in the context');
}

new CdkbasicStack(app, 'CdkbasicStack', {
stackName: `${environment}-lld-cdk-basic`,
Expand Down
4 changes: 2 additions & 2 deletions test/cdk-esm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('cdk-esm', async () => {

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

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

test('remove infra', async () => {
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
await removeInfra(lldProcess, folder);
await removeInfra(lldProcess, folder, ['-c environment=test']);
const lambdaName = await getFunctionName(
folder,
'FunctionNameTestTsCommonJs',
Expand Down
6 changes: 5 additions & 1 deletion test/cdk-esm/bin/cdk-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { CdkEsmStack2 } from '../lib/subfolder/cdk-esm-stack2';

const app = new cdk.App();

const environment = 'test';
const environment = app.node.tryGetContext('environment');

if (!environment) {
throw new Error('Environment is not set in the context');
}

new CdkEsmStack(app, 'CdkEsmStack', {
stackName: `${environment}-lld-cdk-esm`,
Expand Down
2 changes: 1 addition & 1 deletion test/terraform-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('terraform-basic', async () => {

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

Expand Down

0 comments on commit 86c2cae

Please sign in to comment.