Skip to content

Commit b557b82

Browse files
committed
tests: show context.log() output upon failure
Since we mock away the `log()` function, the output is hidden from the user. But in case of failures, that output is really valuable in diagnosing issues! So let's intercept the exceptions and show the output before re-throwing them. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 0e36b66 commit b557b82

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

__tests__/index.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ const makeContext = (body, headers) => {
8282
}
8383
}
8484

85-
const mockIssueComment = (comment) => {
86-
return makeContext({
85+
const testIssueComment = (comment, fn) => {
86+
const context = makeContext({
8787
action: 'created',
8888
comment: {
8989
body: comment,
@@ -108,10 +108,18 @@ const mockIssueComment = (comment) => {
108108
}, {
109109
'x-github-event': 'issue_comment'
110110
})
111+
112+
test(`test ${comment}`, async () => {
113+
try {
114+
await fn(context)
115+
} catch (e) {
116+
context.log.mock.calls.forEach(e => console.log(e[0]))
117+
throw e;
118+
}
119+
})
111120
}
112121

113-
test('test /hi', async () => {
114-
const context = mockIssueComment('/hi')
122+
testIssueComment('/hi', async (context) => {
115123
expect(await index(context, context.req)).toBeUndefined()
116124
expect(context.res).toEqual({
117125
body: 'I said hi! new-comment-url-Hi @statler and waldorf!',

0 commit comments

Comments
 (0)