diff --git a/packages/cdktf-cli/src/bin/cmds/ui/synth.tsx b/packages/cdktf-cli/src/bin/cmds/ui/synth.tsx
index 3b65c34fb1..36723078b3 100644
--- a/packages/cdktf-cli/src/bin/cmds/ui/synth.tsx
+++ b/packages/cdktf-cli/src/bin/cmds/ui/synth.tsx
@@ -22,11 +22,16 @@ interface SynthConfig extends CommonSynthConfig {
type SynthOutputConfig = {
stacks: SynthesizedStack[];
};
-const SynthOutput = ({ stacks }: SynthOutputConfig): React.ReactElement => {
+export const SynthOutput = ({
+ stacks,
+}: SynthOutputConfig): React.ReactElement => {
return (
- Generated Terraform code for the stacks:{" "}
- {stacks?.map((s) => s.name).join(", ")}
+ {stacks?.length
+ ? `Generated Terraform code for the stacks: ${stacks
+ .map((s) => s.name)
+ .join(", ")}`
+ : "No stacks found in configuration."}
);
};
diff --git a/packages/cdktf-cli/src/test/ui/synth.test.tsx b/packages/cdktf-cli/src/test/ui/synth.test.tsx
new file mode 100644
index 0000000000..920b772276
--- /dev/null
+++ b/packages/cdktf-cli/src/test/ui/synth.test.tsx
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) HashiCorp, Inc.
+ * SPDX-License-Identifier: MPL-2.0
+ */
+
+import React from "react";
+import { render } from "ink-testing-library";
+import { stripAnsi } from "../test-helper";
+import { SynthOutput } from "../../bin/cmds/ui/synth";
+import { SynthesizedStack } from "@cdktf/cli-core";
+
+test("SynthOutput", () => {
+ const { lastFrame } = render(
+
+ ,
+
+ );
+ expect(stripAnsi(lastFrame())).toBe("No stacks found in configuration.");
+ {
+ const multipleStacks = [
+ { name: "stack1" },
+ { name: "stack2" },
+ ] as SynthesizedStack[];
+
+ const { lastFrame } = render(
+
+ ,
+
+ );
+ expect(stripAnsi(lastFrame())).toBe(
+ "Generated Terraform code for the stacks: stack1, stack2"
+ );
+ }
+});