@@ -2,6 +2,7 @@ import * as SentryCore from '@sentry/core';
22import { Hono } from 'hono' ;
33import { afterAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
44import { patchAppUse } from '../../src/shared/patchAppUse' ;
5+ import { patchRoute } from '../../src/shared/patchRoute' ;
56
67vi . mock ( '@sentry/core' , async ( ) => {
78 const actual = await vi . importActual ( '@sentry/core' ) ;
@@ -164,9 +165,14 @@ describe('patchAppUse (middleware spans)', () => {
164165 } ) ;
165166
166167 describe ( 'route() patching (sub-app / route group support)' , ( ) => {
168+ beforeEach ( ( ) => {
169+ honoBaseProto . route = originalRoute ;
170+ } ) ;
171+
167172 it ( 'wraps middleware on sub-apps mounted via route()' , async ( ) => {
168173 const app = new Hono ( ) ;
169174 patchAppUse ( app ) ;
175+ patchRoute ( app ) ;
170176
171177 const subApp = new Hono ( ) ;
172178 subApp . use ( async function subMiddleware ( _c : unknown , next : ( ) => Promise < void > ) {
@@ -184,6 +190,7 @@ describe('patchAppUse (middleware spans)', () => {
184190 it ( 'does not wrap route handlers (only method ALL from use())' , async ( ) => {
185191 const app = new Hono ( ) ;
186192 patchAppUse ( app ) ;
193+ patchRoute ( app ) ;
187194
188195 const subApp = new Hono ( ) ;
189196 subApp . get ( '/' , ( ) => new Response ( 'sub' ) ) ;
@@ -198,6 +205,7 @@ describe('patchAppUse (middleware spans)', () => {
198205 it ( 'does not double-wrap handlers already wrapped by patchAppUse on the main app' , async ( ) => {
199206 const app = new Hono ( ) ;
200207 patchAppUse ( app ) ;
208+ patchRoute ( app ) ;
201209
202210 app . use ( async function mainMiddleware ( _c : unknown , next : ( ) => Promise < void > ) {
203211 await next ( ) ;
@@ -214,21 +222,21 @@ describe('patchAppUse (middleware spans)', () => {
214222 expect ( startInactiveSpanMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { name : 'mainMiddleware' } ) ) ;
215223 } ) ;
216224
217- it ( 'does not patch route() twice when patchAppUse is called multiple times' , ( ) => {
225+ it ( 'does not patch route() twice when patchRoute is called multiple times' , ( ) => {
218226 const app1 = new Hono ( ) ;
219- patchAppUse ( app1 ) ;
227+ patchRoute ( app1 ) ;
220228
221229 const patchedRoute = honoBaseProto . route ;
222230
223231 const app2 = new Hono ( ) ;
224- patchAppUse ( app2 ) ;
232+ patchRoute ( app2 ) ;
225233
226234 expect ( honoBaseProto . route ) . toBe ( patchedRoute ) ;
227235 } ) ;
228236
229237 it ( 'stores the original route via __sentry_original__ for other libraries to unwrap' , ( ) => {
230238 const app = new Hono ( ) ;
231- patchAppUse ( app ) ;
239+ patchRoute ( app ) ;
232240
233241 // oxlint-disable-next-line typescript/no-explicit-any
234242 const sentryOriginal = ( honoBaseProto . route as any ) . __sentry_original__ ;
@@ -238,6 +246,7 @@ describe('patchAppUse (middleware spans)', () => {
238246 it ( 'wraps path-targeted .use("/path", handler) on sub-apps' , async ( ) => {
239247 const app = new Hono ( ) ;
240248 patchAppUse ( app ) ;
249+ patchRoute ( app ) ;
241250
242251 const subApp = new Hono ( ) ;
243252 subApp . use ( '/admin/*' , async function adminAuth ( _c : unknown , next : ( ) => Promise < void > ) {
@@ -254,6 +263,7 @@ describe('patchAppUse (middleware spans)', () => {
254263 it ( 'also wraps .all() handlers on sub-apps (same method: ALL in route record)' , async ( ) => {
255264 const app = new Hono ( ) ;
256265 patchAppUse ( app ) ;
266+ patchRoute ( app ) ;
257267
258268 const subApp = new Hono ( ) ;
259269 subApp . all ( '/catch-all' , async function allHandler ( ) {
@@ -269,6 +279,7 @@ describe('patchAppUse (middleware spans)', () => {
269279 it ( 'wraps mixed .use() and .all() handlers on the same sub-app' , async ( ) => {
270280 const app = new Hono ( ) ;
271281 patchAppUse ( app ) ;
282+ patchRoute ( app ) ;
272283
273284 const subApp = new Hono ( ) ;
274285 subApp . use ( async function mw ( _c : unknown , next : ( ) => Promise < void > ) {
@@ -290,6 +301,7 @@ describe('patchAppUse (middleware spans)', () => {
290301 it ( 'does not wrap .get()/.post()/.put()/.delete() handlers on sub-apps' , async ( ) => {
291302 const app = new Hono ( ) ;
292303 patchAppUse ( app ) ;
304+ patchRoute ( app ) ;
293305
294306 const subApp = new Hono ( ) ;
295307 subApp . get ( '/resource' , async function getHandler ( ) {
@@ -308,6 +320,7 @@ describe('patchAppUse (middleware spans)', () => {
308320 it ( 'wraps middleware in nested sub-apps (sub-app mounting another sub-app)' , async ( ) => {
309321 const app = new Hono ( ) ;
310322 patchAppUse ( app ) ;
323+ patchRoute ( app ) ;
311324
312325 const innerSub = new Hono ( ) ;
313326 innerSub . use ( async function innerMiddleware ( _c : unknown , next : ( ) => Promise < void > ) {
@@ -332,6 +345,7 @@ describe('patchAppUse (middleware spans)', () => {
332345 it ( 'handles sub-app with multiple path-targeted middleware for different paths' , async ( ) => {
333346 const app = new Hono ( ) ;
334347 patchAppUse ( app ) ;
348+ patchRoute ( app ) ;
335349
336350 const subApp = new Hono ( ) ;
337351 subApp . use ( '/a/*' , async function mwForA ( _c : unknown , next : ( ) => Promise < void > ) {
0 commit comments