@@ -407,6 +407,62 @@ d.replaceWith(c.content)
407407 expect ( await res . text ( ) ) . toBe ( '<!DOCTYPE html><div>Hi</div>' )
408408 } )
409409
410+ it ( 'Should accept function-based options' , async ( ) => {
411+ type Env = { Bindings : { HONO_STREAMING ?: boolean } }
412+ const app = new Hono < Env > ( )
413+
414+ const Component = async ( ) => {
415+ return < div > Component</ div >
416+ }
417+
418+ app . use (
419+ '*' ,
420+ jsxRenderer < Env > (
421+ ( { children } ) => {
422+ return (
423+ < html >
424+ < body > { children } </ body >
425+ </ html >
426+ )
427+ } ,
428+ ( c ) => {
429+ expectTypeOf ( c . env ?. HONO_STREAMING ) . toEqualTypeOf < boolean | undefined > ( )
430+ return { docType : true , stream : c . env ?. HONO_STREAMING ?? true }
431+ }
432+ )
433+ )
434+
435+ app . get ( '/' , async ( c ) => {
436+ return c . render (
437+ < div >
438+ < Suspense fallback = { 'loading...' } >
439+ < Component />
440+ </ Suspense >
441+ </ div > ,
442+ { title : 'Suspense test' }
443+ )
444+ } )
445+
446+ const resStream = await app . request ( '/' )
447+ expect ( resStream . status ) . toBe ( 200 )
448+ expect ( resStream . headers . get ( 'Transfer-Encoding' ) ) . toBe ( 'chunked' )
449+ const textStream = await resStream . text ( )
450+ expect ( textStream ) . toContain ( '<template' )
451+ expect ( textStream ) . toContain ( '<script' )
452+ expect ( textStream ) . toContain ( 'loading...' )
453+
454+ const resNotStream = await app . request ( '/' , undefined , { HONO_STREAMING : false } )
455+ expect ( resNotStream . status ) . toBe ( 200 )
456+ expect ( resNotStream . headers . get ( 'Transfer-Encoding' ) ) . toBeNull ( )
457+ const textNotStream = await resNotStream . text ( )
458+ expect ( textNotStream ) . not . toContain ( '<template' )
459+ expect ( textNotStream ) . not . toContain ( '<script' )
460+ expect ( textNotStream ) . not . toContain ( 'loading...' )
461+ expect ( textNotStream ) . toBe (
462+ '<!DOCTYPE html><html><body><div><div>Component</div></div></body></html>'
463+ )
464+ } )
465+
410466 describe ( 'keep context status' , async ( ) => {
411467 it ( 'Should keep context status' , async ( ) => {
412468 const app = new Hono ( )
0 commit comments