@@ -8,6 +8,8 @@ const t = require('tap')
88const simple = require ( 'simple-get' )
99const Fastify = require ( 'fastify' )
1010const compress = require ( 'fastify-compress' )
11+ const concat = require ( 'concat-stream' )
12+ const pino = require ( 'pino' )
1113
1214const fastifyStatic = require ( '../' )
1315
@@ -592,14 +594,22 @@ t.test('prefix default', t => {
592594 t . doesNotThrow ( ( ) => fastify . register ( fastifyStatic , pluginOptions ) )
593595} )
594596
595- t . test ( 'root not found error ' , t => {
596- t . plan ( 1 )
597+ t . test ( 'root not found warning ' , t => {
598+ t . plan ( 2 )
597599 const rootPath = path . join ( __dirname , 'does-not-exist' )
598600 const pluginOptions = { root : rootPath }
599- const fastify = Fastify ( { logger : false } )
601+ const destination = concat ( data => {
602+ t . equal ( JSON . parse ( data ) . msg , `"root" path "${ rootPath } " must exist` )
603+ } )
604+ const logger = pino ( {
605+ level : 'warn'
606+ } , destination )
607+ const fastify = Fastify ( { logger : logger } )
600608 fastify . register ( fastifyStatic , pluginOptions )
601609 fastify . listen ( 0 , err => {
602- t . equal ( err . message , `"root" path "${ rootPath } " must exist` )
610+ t . error ( err )
611+ fastify . server . unref ( )
612+ destination . end ( )
603613 } )
604614} )
605615
@@ -673,7 +683,7 @@ t.test('setHeaders option', t => {
673683} )
674684
675685t . test ( 'errors' , t => {
676- t . plan ( 6 )
686+ t . plan ( 5 )
677687
678688 t . test ( 'no root' , t => {
679689 t . plan ( 1 )
@@ -705,16 +715,6 @@ t.test('errors', t => {
705715 } )
706716 } )
707717
708- t . test ( 'root doesn\'t exist' , t => {
709- t . plan ( 1 )
710- const pluginOptions = { root : path . join ( __dirname , 'foo' , 'bar' ) }
711- const fastify = Fastify ( { logger : false } )
712- fastify . register ( fastifyStatic , pluginOptions )
713- . ready ( err => {
714- t . equal ( err . constructor , Error )
715- } )
716- } )
717-
718718 t . test ( 'root is not a directory' , t => {
719719 t . plan ( 1 )
720720 const pluginOptions = { root : __filename }
0 commit comments