Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/cli/io-host/cli-io-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ export class CliIoHost implements IIoHost, ObservableIoHost {
}

// respond with the default for all other messages
if (msg.defaultResponse) {
if (msg.defaultResponse !== undefined) {
await this.writeMessage({
...msg,
message: `${chalk.cyan(msg.message)} (auto-responded with default: ${util.format(msg.defaultResponse)})`,
Expand Down
31 changes: 31 additions & 0 deletions packages/aws-cdk/test/cli/io-host/cli-io-host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,37 @@ describe('CliIoHost', () => {
}));
expect(response).toBe('foobar');
});

test('falsy defaults (empty string, zero) are auto-responded instead of requiring a TTY', async () => {
const nonTtyAutoRespondingIoHost = CliIoHost.instance({
logLevel: 'trace',
autoRespond: true,
isCI: false,
isTTY: false,
}, true);

// empty string default
const stringResponse = await nonTtyAutoRespondingIoHost.requestResponse(plainMessage({
time: new Date(),
level: 'info',
action: 'synth',
code: 'CDK_TOOLKIT_I5060',
message: 'test message',
defaultResponse: '',
}));
expect(stringResponse).toBe('');

// zero default
const numberResponse = await nonTtyAutoRespondingIoHost.requestResponse(plainMessage({
time: new Date(),
level: 'info',
action: 'synth',
code: 'CDK_TOOLKIT_I0001',
message: 'test message',
defaultResponse: 0,
}));
expect(numberResponse).toBe(0);
});
});

describe('non-promptable data', () => {
Expand Down
Loading