From 9b8cfb6f05310456f4873bffdc4ae9e351ca2aef Mon Sep 17 00:00:00 2001 From: HBobertz Date: Fri, 10 Jan 2025 00:03:32 -0500 Subject: [PATCH] add test for code cov --- .../aws-cdk/test/toolkit/cli-io-host.test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/aws-cdk/test/toolkit/cli-io-host.test.ts b/packages/aws-cdk/test/toolkit/cli-io-host.test.ts index 100d619d2dbb1..f293f50ac3025 100644 --- a/packages/aws-cdk/test/toolkit/cli-io-host.test.ts +++ b/packages/aws-cdk/test/toolkit/cli-io-host.test.ts @@ -122,6 +122,47 @@ describe('CliIoHost', () => { expect(mockStdout).toHaveBeenCalledWith('test message\n'); }); + test('default value matches process.stdout.isTTY', () => { + const expectedTTY = process.stdout.isTTY ?? false; + expect(CliIoHost.isTTY).toBe(expectedTTY); + }); + + test('setting isTTY affects message formatting', async () => { + const mockStdout = jest.fn(); + jest.spyOn(process.stdout, 'write').mockImplementation((str: any, encoding?: any, cb?: any) => { + mockStdout(str.toString()); + const callback = typeof encoding === 'function' ? encoding : cb; + if (callback) callback(); + return true; + }); + + // Test with TTY enabled + CliIoHost.isTTY = true; + await CliIoHost.getIoHost().notify({ + time: new Date('2024-01-01T12:00:00'), + level: 'info', + action: 'synth', + code: 'TEST_0001', + message: 'test message', + forceStdout: true + }); + expect(mockStdout).toHaveBeenLastCalledWith(expect.stringContaining('\u001b')); // Should contain ANSI color codes + + // Test with TTY disabled + CliIoHost.isTTY = false; + await CliIoHost.getIoHost().notify({ + time: new Date('2024-01-01T12:00:00'), + level: 'info', + action: 'synth', + code: 'TEST_0001', + message: 'test message', + forceStdout: true + }); + expect(mockStdout).toHaveBeenLastCalledWith('test message\n'); // Should not contain ANSI color codes + + jest.restoreAllMocks(); + }); + test('applies correct color styles for different message levels', async () => { const testCases = [ { level: 'error' as const, style: chalk.red },