Fix getSentry() issue
parent
ca742a2ea3
commit
8e290c0b70
|
@ -1,5 +1,5 @@
|
|||
import type { Context, Handler } from 'https://raw.githubusercontent.com/honojs/hono/v2.0.6/deno_dist/mod.ts'
|
||||
import Toucan from "https://cdn.skypack.dev/toucan-js@2.6.1"
|
||||
import Toucan from 'https://cdn.skypack.dev/toucan-js@2.6.1'
|
||||
|
||||
declare module 'https://raw.githubusercontent.com/honojs/hono/v2.0.6/deno_dist/mod.ts' {
|
||||
interface ContextVariableMap {
|
||||
|
@ -45,7 +45,7 @@ export const sentry = (options?: Options, callback?: (sentry: Toucan) => void):
|
|||
context: hasExecutionContext ? c.executionCtx : new MockContext(),
|
||||
...options,
|
||||
})
|
||||
|
||||
c.set('sentry', sentry)
|
||||
if (callback) callback(sentry)
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@honojs/sentry",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "Sentry Middleware for Hono",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
@ -45,7 +45,7 @@ export const sentry = (options?: Options, callback?: (sentry: Toucan) => void):
|
|||
context: hasExecutionContext ? c.executionCtx : new MockContext(),
|
||||
...options,
|
||||
})
|
||||
|
||||
c.set('sentry', sentry)
|
||||
if (callback) callback(sentry)
|
||||
|
||||
try {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { makeThisModuleAnExecutableReplacer } from 'denoify'
|
|||
|
||||
makeThisModuleAnExecutableReplacer(async ({ parsedImportExportStatement, version }) => {
|
||||
if (parsedImportExportStatement.parsedArgument.nodeModuleName === 'toucan-js') {
|
||||
return `import Toucan from "https://cdn.skypack.dev/toucan-js@${version}"`
|
||||
return `import Toucan from 'https://cdn.skypack.dev/toucan-js@${version}'`
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Hono } from 'hono'
|
||||
import { sentry } from '../src'
|
||||
import { sentry, getSentry } from '../src'
|
||||
|
||||
// Mock
|
||||
class Context implements ExecutionContext {
|
||||
|
@ -12,7 +12,8 @@ class Context implements ExecutionContext {
|
|||
}
|
||||
|
||||
const captureException = jest.fn()
|
||||
jest.mock('toucan-js', () => jest.fn().mockImplementation(() => ({ captureException })))
|
||||
const log = jest.fn()
|
||||
jest.mock('toucan-js', () => jest.fn().mockImplementation(() => ({ captureException, log })))
|
||||
const callback = jest.fn()
|
||||
|
||||
describe('Sentry middleware', () => {
|
||||
|
@ -20,6 +21,7 @@ describe('Sentry middleware', () => {
|
|||
|
||||
app.use('/sentry/*', sentry(undefined, callback))
|
||||
app.get('/sentry/foo', (c) => c.text('foo'))
|
||||
app.get('/sentry/bar', (c) => getSentry(c).log('bar') && c.text('bar'))
|
||||
app.get('/sentry/error', () => {
|
||||
throw new Error('a catastrophic error')
|
||||
})
|
||||
|
@ -32,6 +34,14 @@ describe('Sentry middleware', () => {
|
|||
expect(callback).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('Should make Sentry available via context', async () => {
|
||||
const req = new Request('http://localhost/sentry/bar')
|
||||
const res = await app.fetch(req, {}, new Context())
|
||||
expect(res).not.toBeNull()
|
||||
expect(res.status).toBe(500)
|
||||
expect(log).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('Should report errors', async () => {
|
||||
const req = new Request('http://localhost/sentry/error')
|
||||
const res = await app.fetch(req, {}, new Context())
|
||||
|
|
Loading…
Reference in New Issue