honojs-middleware/packages/sentry/deno_test/index.test.ts

30 lines
899 B
TypeScript
Raw Normal View History

2022-08-13 03:55:30 +08:00
import { assertNotEquals } from 'https://deno.land/std@0.148.0/testing/asserts.ts'
2022-08-10 00:32:06 +08:00
import { sentry } from '../deno_dist/mod.ts'
2022-08-04 07:54:30 +08:00
import { assertEquals, Hono } from './deps.ts'
// Test just only minimal patterns.
// Because others are tested well in Cloudflare Workers environment already.
2022-08-10 00:32:06 +08:00
Deno.test('Sentry Middleware', async () => {
2022-08-04 07:54:30 +08:00
const app = new Hono()
2022-08-13 03:57:37 +08:00
app.use(
'/sentry/*',
sentry(undefined, (sentry) => {
2022-08-13 03:58:16 +08:00
sentry.setUser({ id: 'test' })
2022-08-13 03:57:37 +08:00
})
)
2022-08-10 00:32:06 +08:00
app.get('/sentry/foo', (c) => c.text('foo'))
2022-08-13 03:55:30 +08:00
app.get('/sentry/error', () => {
throw new Error('a catastrophic error')
})
2022-08-04 07:54:30 +08:00
2022-08-13 03:55:30 +08:00
let req = new Request('http://localhost/sentry/foo')
let res = await app.fetch(req)
2022-08-13 03:55:30 +08:00
assertNotEquals(res, null)
2022-08-04 07:54:30 +08:00
assertEquals(res.status, 200)
2022-08-13 03:55:30 +08:00
req = new Request('http://localhost/sentry/error')
res = await app.fetch(req)
2022-08-13 03:55:30 +08:00
assertNotEquals(res, null)
assertEquals(res.status, 500)
2022-08-04 07:54:30 +08:00
})