@@ -3682,3 +3682,110 @@ describe('Handlers returning Promise<void>', () => {
36823682 type verify = Expect < Equal < Expected , Actual > >
36833683 } )
36843684} )
3685+
3686+ // Regression tests for #4388: routes before .use() with explicit paths should not be dropped
3687+ describe ( 'Routes before .use() with explicit paths (#4388)' , ( ) => {
3688+ it ( 'should preserve explicit-path .get() before .use() with path' , ( ) => {
3689+ const app = new Hono ( )
3690+ . get ( '/' , ( c ) => c . text ( 'Hello from /' ) )
3691+ . use ( '/noop' , async ( c , next ) => {
3692+ await next ( )
3693+ } )
3694+
3695+ type Actual = ExtractSchema < typeof app >
3696+ type Expected = {
3697+ '/' : {
3698+ $get : {
3699+ input : { }
3700+ output : 'Hello from /'
3701+ outputFormat : 'text'
3702+ status : ContentfulStatusCode
3703+ }
3704+ }
3705+ }
3706+ type verify = Expect < Equal < Expected , Actual > >
3707+ } )
3708+
3709+ it ( 'should preserve .get() route and infer .post() under .use() path' , ( ) => {
3710+ const app = new Hono ( )
3711+ . get ( '/' , ( c ) => c . text ( 'Hello from /' ) )
3712+ . use ( '/:slug' , async ( c , next ) => {
3713+ await next ( )
3714+ } )
3715+ . post ( ( c ) => c . text ( 'posted' ) )
3716+
3717+ type Actual = ExtractSchema < typeof app >
3718+ type Expected = {
3719+ '/' : {
3720+ $get : {
3721+ input : { }
3722+ output : 'Hello from /'
3723+ outputFormat : 'text'
3724+ status : ContentfulStatusCode
3725+ }
3726+ }
3727+ } & {
3728+ '/:slug' : {
3729+ $post : {
3730+ input : {
3731+ param : {
3732+ slug : string
3733+ }
3734+ }
3735+ output : 'posted'
3736+ outputFormat : 'text'
3737+ status : ContentfulStatusCode
3738+ }
3739+ }
3740+ }
3741+ type verify = Expect < Equal < Expected , Actual > >
3742+ } )
3743+
3744+ it ( 'should preserve routes through .route() wrapping' , ( ) => {
3745+ const inner = new Hono ( )
3746+ . get ( '/' , ( c ) => c . text ( 'index' ) )
3747+ . use ( '/:slug' , async ( c , next ) => {
3748+ await next ( )
3749+ } )
3750+ . post ( ( c ) => c . text ( 'posted' ) )
3751+
3752+ const app = new Hono ( ) . route ( '/api' , inner )
3753+
3754+ const client = hc < typeof app > ( 'http://localhost' )
3755+ // '/api' $get should exist (from inner .get('/'))
3756+ expectTypeOf ( client . api . $get ) . toBeFunction ( )
3757+ // '/api/:slug' $post should exist (from inner .post() after .use('/:slug'))
3758+ expectTypeOf ( client . api [ ':slug' ] . $post ) . toBeFunction ( )
3759+ } )
3760+
3761+ it ( 'should preserve multiple explicit-path routes before .use()' , ( ) => {
3762+ const app = new Hono ( )
3763+ . get ( '/' , ( c ) => c . text ( 'home' ) )
3764+ . get ( '/about' , ( c ) => c . text ( 'about' ) )
3765+ . use ( '/mw' , async ( c , next ) => {
3766+ await next ( )
3767+ } )
3768+
3769+ type Actual = ExtractSchema < typeof app >
3770+ type Expected = {
3771+ '/' : {
3772+ $get : {
3773+ input : { }
3774+ output : 'home'
3775+ outputFormat : 'text'
3776+ status : ContentfulStatusCode
3777+ }
3778+ }
3779+ } & {
3780+ '/about' : {
3781+ $get : {
3782+ input : { }
3783+ output : 'about'
3784+ outputFormat : 'text'
3785+ status : ContentfulStatusCode
3786+ }
3787+ }
3788+ }
3789+ type verify = Expect < Equal < Expected , Actual > >
3790+ } )
3791+ } )
0 commit comments