Skip to content

Commit 7be9068

Browse files
authored
chore: remove parentheses in 'sam local start-api' filter (#24508)
The dependencies in v1.76.0+ of the SAM CLI no longer contain parenthesis in the output, making the trigger wait forever
1 parent 9237a7a commit 7be9068

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

packages/@aws-cdk-testing/cli-integ/lib/with-sam.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class SamIntegrationTestFixture extends TestFixture {
140140
args.push('--port');
141141
args.push(port.toString());
142142

143-
return this.samShell(['sam', 'local', 'start-api', ...args], '(Press CTRL+C to quit)', ()=>{
143+
return this.samShell(['sam', 'local', 'start-api', ...args], 'Press CTRL+C to quit', ()=>{
144144
return new Promise<ActionOutput>((resolve, reject) => {
145145
axios.get(`http://127.0.0.1:${port}${apiPath}`).then( resp => {
146146
resolve(resp.data);
@@ -173,7 +173,12 @@ export function randomInteger(min: number, max: number) {
173173
* Is platform-aware, handles errors nicely.
174174
*/
175175
export async function shellWithAction(
176-
command: string[], filter?: string, action?: () => Promise<any>, options: ShellOptions = {}): Promise<ActionOutput> {
176+
command: string[],
177+
filter?: string,
178+
action?: () => Promise<any>,
179+
options: ShellOptions = {},
180+
actionTimeoutSeconds: number = 600,
181+
): Promise<ActionOutput> {
177182
if (options.modEnv && options.env) {
178183
throw new Error('Use either env or modEnv but not both');
179184
}
@@ -199,8 +204,8 @@ export async function shellWithAction(
199204
let actionExecuted = false;
200205

201206
function executeAction(chunk: any) {
202-
out.push(chunk);
203-
if (!actionExecuted && typeof filter === 'string' && out.toString().includes(filter) && typeof action === 'function') {
207+
out.push(Buffer.from(chunk));
208+
if (!actionExecuted && typeof filter === 'string' && Buffer.concat(out).toString('utf-8').includes(filter) && typeof action === 'function') {
204209
actionExecuted = true;
205210
options.output?.write('before executing action');
206211
action().then((output) => {
@@ -218,6 +223,18 @@ export async function shellWithAction(
218223
}
219224
}
220225

226+
if (typeof filter === 'string' && typeof action === 'function') {
227+
// Reject with an error if an action is configured, but the filter failed
228+
// to show up in the output before the timeout occurred.
229+
setTimeout(
230+
() => {
231+
if (!actionExecuted) {
232+
reject(new Error(`Timed out waiting for filter ${JSON.stringify(filter)} to appear in command output after ${actionTimeoutSeconds} seconds\nOutput so far:\n${Buffer.concat(out).toString('utf-8')}`));
233+
}
234+
}, actionTimeoutSeconds * 1_000,
235+
).unref();
236+
}
237+
221238
child.stdout!.on('data', chunk => {
222239
options.output?.write(chunk);
223240
stdout.push(chunk);

0 commit comments

Comments
 (0)