Skip to content

Commit

Permalink
fix: handle no mock args (#6659)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle authored Feb 17, 2021
1 parent f82b069 commit 6b97ffa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/amplify-util-mock/src/__tests__/func/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,16 @@ describe('function start', () => {
expect(inquirer_mock.prompt.mock.calls[0][0][0].choices).toStrictEqual(['func1', 'func2', 'func3']);
expect(getBuilder_mock.mock.calls[0][1]).toBe('func2');
});

it('handles no options specified', async () => {
const invoker = jest.fn().mockResolvedValue(null);
getInvoker_mock.mockResolvedValueOnce(invoker);
inquirer_mock.prompt.mockResolvedValueOnce({ eventName: 'event.json' });

const context_stub_copy = _.merge({}, context_stub);
context_stub_copy.input.options = undefined;
await start(context_stub_copy);
expect(invoker.mock.calls.length).toBe(1);
expect(context_stub_copy.print.error.mock.calls.length).toBe(0);
});
});
4 changes: 2 additions & 2 deletions packages/amplify-util-mock/src/func/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function start(context: $TSContext) {
interface InvokerOptions {
timeout?: string;
}
export const timeConstrainedInvoker = async <T>(promise: Promise<T>, options: InvokerOptions): Promise<T> => {
export const timeConstrainedInvoker = async <T>(promise: Promise<T>, options?: InvokerOptions): Promise<T> => {
const { timer, cancel } = getCancellableTimer(options);
try {
return await Promise.race([promise, timer]);
Expand All @@ -70,7 +70,7 @@ export const timeConstrainedInvoker = async <T>(promise: Promise<T>, options: In
}
};

const getCancellableTimer = ({ timeout }: InvokerOptions) => {
const getCancellableTimer = ({ timeout }: InvokerOptions = {}) => {
const inputTimeout = Number.parseInt(timeout, 10);
const lambdaTimeoutSeconds = !!inputTimeout && inputTimeout > 0 ? inputTimeout : DEFAULT_TIMEOUT_SECONDS;
const timeoutErrorMessage = `Lambda execution timed out after ${lambdaTimeoutSeconds} seconds. Press ctrl + C to exit the process.
Expand Down

0 comments on commit 6b97ffa

Please sign in to comment.