Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/cdktf-cli/src/bin/cmds/ui/synth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Text>
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 the configuration."}
</Text>
);
};
Expand Down
27 changes: 27 additions & 0 deletions packages/cdktf-cli/src/test/ui/synth.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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 shows message when no stacks are found", () => {
const { lastFrame } = render(<SynthOutput stacks={[]} />);
expect(stripAnsi(lastFrame())).toBe("No stacks found in the configuration.");
});

test("SynthOutput lists multiple stack names", () => {
const multipleStacks = [
{ name: "stack1" },
{ name: "stack2" },
] as SynthesizedStack[];

const { lastFrame } = render(<SynthOutput stacks={multipleStacks} />);
expect(stripAnsi(lastFrame())).toBe(
"Generated Terraform code for the stacks: stack1, stack2",
);
});
Loading