Skip to content

Commit

Permalink
add test for code cov
Browse files Browse the repository at this point in the history
  • Loading branch information
HBobertz committed Jan 10, 2025
1 parent 3e9cfd6 commit 9b8cfb6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/aws-cdk/test/toolkit/cli-io-host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit 9b8cfb6

Please # to comment.