Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HBobertz committed Dec 30, 2024
1 parent 35c928d commit 3b98e84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/private/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export async function shell(command: string[], options: ShellOptions = {}): Prom
child.once('close', (code, signal) => {
if (code === 0) {
const output = Buffer.concat(stdout).toString('utf-8');
globalOutputHandler.publishEvent(EventType.SUCCESS, output);
resolve(output);
} else {
const errorOutput = Buffer.concat(stderr).toString('utf-8').trim();
Expand All @@ -63,7 +62,6 @@ export async function shell(command: string[], options: ShellOptions = {}): Prom
signal,
`${renderCommandLine(command)} exited with ${code != null ? 'error code' : 'signal'} ${code ?? signal}: ${errorOutput}`
);
globalOutputHandler.publishEvent(EventType.FAIL, error.message);
reject(error);
}
});
Expand Down
11 changes: 6 additions & 5 deletions test/asset-publishing-logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('Shell Command Logging', () => {
jest.clearAllMocks();
});

test('captures both stdout and stderr from shell commands', async () => {
test('docker successfully emits publishing events when publishing asset', async () => {
const messages: string[] = [];
const aws = new MockAws();

Expand All @@ -315,12 +315,10 @@ describe('Shell Command Logging', () => {
'--password-stdin',
'https://12345.dkr.ecr.region.amazonaws.com',
],
stdout: 'Login Succeeded',
},
{
commandLine: ['docker', 'inspect', 'cdkasset-thedockerasset'],
exitCode: 1,
stderr: 'Warning: using default credentials\n',
},
{
commandLine: ['docker', 'build', '--tag', 'cdkasset-thedockerasset', '.'],
Expand All @@ -345,8 +343,11 @@ describe('Shell Command Logging', () => {
// Check that both stdout and stderr were captured
expect(messages).toEqual(
expect.arrayContaining([
expect.stringContaining('Login Succeeded'),
expect.stringContaining('Warning: using default credentials'),
expect.stringContaining('Publishing theDockerAsset:theDestination'),
expect.stringContaining('Check 12345.dkr.ecr.region.amazonaws.com/repo:tag'),
expect.stringContaining('Building Docker image at '),
expect.stringContaining('Push 12345.dkr.ecr.region.amazonaws.com/repo:tag'),
expect.stringContaining('Published theDockerAsset:theDestination'),
])
);
});
Expand Down

0 comments on commit 3b98e84

Please sign in to comment.