diff --git a/GitGitGadget/index.js b/GitGitGadget/index.js index c26145e..17623e0 100644 --- a/GitGitGadget/index.js +++ b/GitGitGadget/index.js @@ -21,7 +21,6 @@ module.exports = async (context, req) => { status: 403, body: 'Not a valid GitHub webhook: ' + e, }; - context.done(); return; } @@ -112,7 +111,6 @@ module.exports = async (context, req) => { context.res = { body: `Not a command: '${comment.body}'`, }; - context.done(); return; } @@ -131,12 +129,10 @@ module.exports = async (context, req) => { }; } } catch (e) { - context.log('Caught exception ' + e); + context.log('Caught exception ', e); context.res = { status: 500, - body: 'Caught an error: ' + e, + body: `Caught an error: ${e.message || JSON.stringify(e, null, 2)}`, }; } - - context.done(); }; diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 7db164e..797d958 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -49,7 +49,7 @@ test('reject requests other than webhook payloads', async () => { body: `Not a valid GitHub webhook: Error: ${message}`, status: 403 }) - expect(context.done).toHaveBeenCalledTimes(1) + expect(context.done).not.toHaveBeenCalled() } await expectInvalidWebhook('Unexpected content type: text/plain') @@ -142,7 +142,7 @@ const testIssueComment = (comment, repoOwner, fn) => { try { expect(await index(context, context.req)).toBeUndefined() await fn(context) - expect(context.done).toHaveBeenCalledTimes(1) + expect(context.done).not.toHaveBeenCalled() } catch (e) { context.log.mock.calls.forEach(e => console.log(e[0])) throw e; @@ -151,7 +151,7 @@ const testIssueComment = (comment, repoOwner, fn) => { } testIssueComment('/test', async (context) => { - expect(context.done).toHaveBeenCalledTimes(1) + expect(context.done).not.toHaveBeenCalled() expect(context.res).toEqual({ body: 'Okay, triggered !' }) @@ -160,7 +160,7 @@ testIssueComment('/test', async (context) => { }) testIssueComment('/verify-repository', 'nope', (context) => { - expect(context.done).toHaveBeenCalledTimes(1) + expect(context.done).not.toHaveBeenCalled() expect(context.res).toEqual({ body: 'Refusing to work on a repository other than gitgitgadget/git or git/git', 'status': 403, @@ -178,7 +178,7 @@ const testWebhookPayload = (testLabel, gitHubEvent, payload, fn) => { try { expect(await index(context, context.req)).toBeUndefined() await fn(context) - expect(context.done).toHaveBeenCalledTimes(1) + expect(context.done).not.toHaveBeenCalled() } catch (e) { context.log.mock.calls.forEach(e => console.log(e[0])) throw e; @@ -305,4 +305,4 @@ testWebhookPayload('react to PR push', 'pull_request', { 'pr-url': 'https://github.com/gitgitgadget/git/pull/1956', } ]) -}) \ No newline at end of file +})