Skip to content

Commit

Permalink
feat: restructure test & console.log -> console.error
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbrugger committed Nov 20, 2023
1 parent 285a772 commit 2114c00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion plugins/record-hook/src/RecordHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const RecordHook = async (
try {
await handler(record, event)
} catch (e) {
console.log(`An error occurred while running the handler: ${e}`)
console.error(
`An error occurred while running the handler: ${e.message}`
)
}
})
)
Expand Down
16 changes: 8 additions & 8 deletions plugins/record-hook/src/record.hook.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,29 @@ describe('recordHook() e2e', () => {
})

describe('recordHook errors', () => {
const logErrorSpy = jest.spyOn(global.console, 'error')
beforeEach(async () => {
listener.use(
recordHook('test', (record) => {
throw new Error('oops')
})
)
})
it('returns readable error', async () => {
const logSpy = jest.spyOn(global.console, 'log')
await createRecords(sheetId, [
{
name: 'John Doe',
email: 'john@doe.com',
notes: 'foobar',
},
])

})
it('returns readable error', async () => {
await listener.waitFor('commit:created')

expect(logSpy).toHaveBeenCalledWith(
'An error occurred while running the handler: Error: oops'
expect(logErrorSpy).toHaveBeenCalledWith(
'An error occurred while running the handler: oops'
)
logSpy.mockRestore()
})
afterEach(() => {
logErrorSpy.mockClear()
})
})
})

0 comments on commit 2114c00

Please sign in to comment.