@@ -715,3 +715,122 @@ t.test('with fastify-compress', t => {
715715 } )
716716 } )
717717} )
718+
719+ t . test ( 'register /static/ with schemaHide true' , t => {
720+ t . plan ( 3 )
721+
722+ const pluginOptions = {
723+ root : path . join ( __dirname , '/static' ) ,
724+ prefix : '/static/' ,
725+ schemaHide : true
726+ }
727+
728+ const fastify = Fastify ( )
729+
730+ fastify . addHook ( 'onRoute' , function ( routeOptions ) {
731+ t . deepEqual ( routeOptions . schema , { hide : true } )
732+ } )
733+
734+ fastify . register ( fastifyStatic , pluginOptions )
735+
736+ t . tearDown ( fastify . close . bind ( fastify ) )
737+
738+ fastify . listen ( 0 , err => {
739+ t . error ( err )
740+
741+ fastify . server . unref ( )
742+
743+ t . test ( '/static/index.html' , t => {
744+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
745+
746+ simple . concat ( {
747+ method : 'GET' ,
748+ url : 'http://localhost:' + fastify . server . address ( ) . port + '/static/index.html'
749+ } , ( err , response , body ) => {
750+ t . error ( err )
751+ t . strictEqual ( response . statusCode , 200 )
752+ t . strictEqual ( body . toString ( ) , indexContent )
753+ genericResponseChecks ( t , response )
754+ } )
755+ } )
756+ } )
757+ } )
758+
759+ t . test ( 'register /static/ with schemaHide false' , t => {
760+ t . plan ( 3 )
761+
762+ const pluginOptions = {
763+ root : path . join ( __dirname , '/static' ) ,
764+ prefix : '/static/' ,
765+ schemaHide : false
766+ }
767+
768+ const fastify = Fastify ( )
769+
770+ fastify . addHook ( 'onRoute' , function ( routeOptions ) {
771+ t . deepEqual ( routeOptions . schema , { hide : false } )
772+ } )
773+
774+ fastify . register ( fastifyStatic , pluginOptions )
775+
776+ t . tearDown ( fastify . close . bind ( fastify ) )
777+
778+ fastify . listen ( 0 , err => {
779+ t . error ( err )
780+
781+ fastify . server . unref ( )
782+
783+ t . test ( '/static/index.html' , t => {
784+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
785+
786+ simple . concat ( {
787+ method : 'GET' ,
788+ url : 'http://localhost:' + fastify . server . address ( ) . port + '/static/index.html'
789+ } , ( err , response , body ) => {
790+ t . error ( err )
791+ t . strictEqual ( response . statusCode , 200 )
792+ t . strictEqual ( body . toString ( ) , indexContent )
793+ genericResponseChecks ( t , response )
794+ } )
795+ } )
796+ } )
797+ } )
798+
799+ t . test ( 'register /static/ without schemaHide' , t => {
800+ t . plan ( 3 )
801+
802+ const pluginOptions = {
803+ root : path . join ( __dirname , '/static' ) ,
804+ prefix : '/static/'
805+ }
806+
807+ const fastify = Fastify ( )
808+
809+ fastify . addHook ( 'onRoute' , function ( routeOptions ) {
810+ t . deepEqual ( routeOptions . schema , { hide : true } )
811+ } )
812+
813+ fastify . register ( fastifyStatic , pluginOptions )
814+
815+ t . tearDown ( fastify . close . bind ( fastify ) )
816+
817+ fastify . listen ( 0 , err => {
818+ t . error ( err )
819+
820+ fastify . server . unref ( )
821+
822+ t . test ( '/static/index.html' , t => {
823+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
824+
825+ simple . concat ( {
826+ method : 'GET' ,
827+ url : 'http://localhost:' + fastify . server . address ( ) . port + '/static/index.html'
828+ } , ( err , response , body ) => {
829+ t . error ( err )
830+ t . strictEqual ( response . statusCode , 200 )
831+ t . strictEqual ( body . toString ( ) , indexContent )
832+ genericResponseChecks ( t , response )
833+ } )
834+ } )
835+ } )
836+ } )
0 commit comments