From 87e5b0f1728f101c3ae00cd49d03df183db3b305 Mon Sep 17 00:00:00 2001 From: razine-bensari Date: Sat, 27 Jan 2024 04:44:57 -0500 Subject: [PATCH 1/4] fix(cli): A bug when opening browser using CLI --- .../src/bin/cmds/helper/terraform-login.ts | 2 +- packages/cdktf-cli/src/test/cmds/init.test.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts b/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts index 91faf5fb5f..2d99c2bdfa 100644 --- a/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts +++ b/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts @@ -72,7 +72,7 @@ the following file for use by subsequent Terraform commands: try { await open.default(this.terraformLoginURL, { allowNonzeroExitCode: true, - wait: true, + wait: false, // Should remain false. Otherwise, it waits for the app (browser) to exit/quit, not just the window. }); } catch (e) { logger.debug( diff --git a/packages/cdktf-cli/src/test/cmds/init.test.ts b/packages/cdktf-cli/src/test/cmds/init.test.ts index c24c162add..c4b82d932d 100644 --- a/packages/cdktf-cli/src/test/cmds/init.test.ts +++ b/packages/cdktf-cli/src/test/cmds/init.test.ts @@ -35,4 +35,29 @@ describe("init command", () => { expect(result.stdout).not.toContain(`Detected Terraform Cloud token.`); }); }, 30_000); + + it("opens up the browser and waits for the token input", async () => { + await mkdtemp(async (cwd) => { + const input = "Y\n"; + const result = await execa( + cdktfBin, + [ + "init", + "--template=go", + "--from-terraform-project=false", + "--enable-crash-reporting=false", + ], + { + stdio: "pipe", + cwd, + input, + } + ); + expect(result.stderr).toEqual(""); + expect(result.stdout).toContain( + `opening webpage using your browser.` + ); + expect(result.stdout).not.toContain(`Token for app.terraform.io`); + }); + }, 30_000); }); From 24ae28208f4f110924073909bf5f1e0006334b57 Mon Sep 17 00:00:00 2001 From: razine-bensari Date: Sat, 27 Jan 2024 04:53:22 -0500 Subject: [PATCH 2/4] chore(cli): invert test assertion --- packages/cdktf-cli/src/test/cmds/init.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cdktf-cli/src/test/cmds/init.test.ts b/packages/cdktf-cli/src/test/cmds/init.test.ts index c4b82d932d..4d4d81be19 100644 --- a/packages/cdktf-cli/src/test/cmds/init.test.ts +++ b/packages/cdktf-cli/src/test/cmds/init.test.ts @@ -57,7 +57,7 @@ describe("init command", () => { expect(result.stdout).toContain( `opening webpage using your browser.` ); - expect(result.stdout).not.toContain(`Token for app.terraform.io`); + expect(result.stdout).toContain(`Token for app.terraform.io`); }); }, 30_000); }); From 92176880be8c31fcdb3178dc0dae025eb8fe4925 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Mon, 5 Feb 2024 10:40:53 +0100 Subject: [PATCH 3/4] chore: run prettier --- packages/cdktf-cli/src/test/cmds/init.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/cdktf-cli/src/test/cmds/init.test.ts b/packages/cdktf-cli/src/test/cmds/init.test.ts index 4d4d81be19..1a9bada611 100644 --- a/packages/cdktf-cli/src/test/cmds/init.test.ts +++ b/packages/cdktf-cli/src/test/cmds/init.test.ts @@ -54,9 +54,7 @@ describe("init command", () => { } ); expect(result.stderr).toEqual(""); - expect(result.stdout).toContain( - `opening webpage using your browser.` - ); + expect(result.stdout).toContain(`opening webpage using your browser.`); expect(result.stdout).toContain(`Token for app.terraform.io`); }); }, 30_000); From c5adf24eabf94fe8b829bf8ba970bbdc8f7cc9d0 Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Mon, 5 Feb 2024 11:35:47 +0100 Subject: [PATCH 4/4] chore: remove test for open as this is not possible to test in CI --- packages/cdktf-cli/src/test/cmds/init.test.ts | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/packages/cdktf-cli/src/test/cmds/init.test.ts b/packages/cdktf-cli/src/test/cmds/init.test.ts index 1a9bada611..c24c162add 100644 --- a/packages/cdktf-cli/src/test/cmds/init.test.ts +++ b/packages/cdktf-cli/src/test/cmds/init.test.ts @@ -35,27 +35,4 @@ describe("init command", () => { expect(result.stdout).not.toContain(`Detected Terraform Cloud token.`); }); }, 30_000); - - it("opens up the browser and waits for the token input", async () => { - await mkdtemp(async (cwd) => { - const input = "Y\n"; - const result = await execa( - cdktfBin, - [ - "init", - "--template=go", - "--from-terraform-project=false", - "--enable-crash-reporting=false", - ], - { - stdio: "pipe", - cwd, - input, - } - ); - expect(result.stderr).toEqual(""); - expect(result.stdout).toContain(`opening webpage using your browser.`); - expect(result.stdout).toContain(`Token for app.terraform.io`); - }); - }, 30_000); });