@@ -514,7 +514,7 @@ t.test('serving disabled', t => {
514514} )
515515
516516t . test ( 'sendFile' , t => {
517- t . plan ( 2 )
517+ t . plan ( 4 )
518518
519519 const pluginOptions = {
520520 root : path . join ( __dirname , '/static' ) ,
@@ -527,6 +527,10 @@ t.test('sendFile', t => {
527527 reply . sendFile ( '/index.html' )
528528 } )
529529
530+ fastify . get ( '/root/path/override/test' , ( request , reply ) => {
531+ reply . sendFile ( '/foo.html' , path . join ( __dirname , 'static' , 'deep' , 'path' , 'for' , 'test' , 'purpose' ) )
532+ } )
533+
530534 fastify . listen ( 0 , err => {
531535 t . error ( err )
532536
@@ -545,6 +549,34 @@ t.test('sendFile', t => {
545549 genericResponseChecks ( t , response )
546550 } )
547551 } )
552+
553+ t . test ( 'reply.sendFile() with rootPath' , t => {
554+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
555+ simple . concat ( {
556+ method : 'GET' ,
557+ url : 'http://localhost:' + fastify . server . address ( ) . port + '/root/path/override/test' ,
558+ followRedirect : false
559+ } , ( err , response , body ) => {
560+ t . error ( err )
561+ t . strictEqual ( response . statusCode , 200 )
562+ t . strictEqual ( body . toString ( ) , deepContent )
563+ genericResponseChecks ( t , response )
564+ } )
565+ } )
566+
567+ t . test ( 'reply.sendFile() again without root path' , t => {
568+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
569+ simple . concat ( {
570+ method : 'GET' ,
571+ url : 'http://localhost:' + fastify . server . address ( ) . port + '/foo/bar' ,
572+ followRedirect : false
573+ } , ( err , response , body ) => {
574+ t . error ( err )
575+ t . strictEqual ( response . statusCode , 200 )
576+ t . strictEqual ( body . toString ( ) , indexContent )
577+ genericResponseChecks ( t , response )
578+ } )
579+ } )
548580 } )
549581} )
550582
0 commit comments