22
33const  {  test }  =  require ( 'tap' ) 
44const  Fastify  =  require ( 'fastify' ) 
5- const  fastifyCompress  =  require ( '..' ) 
6- const  {  request,  setGlobalDispatcher,  Agent }  =  require ( 'undici' ) 
7- 
8- setGlobalDispatcher ( new  Agent ( { 
9-   keepAliveTimeout : 10 , 
10-   keepAliveMaxTimeout : 10 
11- } ) ) 
5+ const  fastifyCompress  =  require ( '../..' ) 
6+ const  fetch  =  require ( 'node-fetch' ) 
127
138test ( 'should not corrupt the file content' ,  async  ( t )  =>  { 
149  // provide 2 byte unicode content 
@@ -25,24 +20,22 @@ test('should not corrupt the file content', async (t) => {
2520  fastify . register ( async  ( instance ,  opts )  =>  { 
2621    await  fastify . register ( fastifyCompress ) 
2722    // compression 
28-     instance . get ( '/issue ' ,  async  ( req ,  reply )  =>  { 
23+     instance . get ( '/compress ' ,  async  ( req ,  reply )  =>  { 
2924      return  twoByteUnicodeContent 
3025    } ) 
3126  } ) 
3227
3328  // no compression 
34-   fastify . get ( '/good ' ,  async  ( req ,  reply )  =>  { 
29+   fastify . get ( '/no-compress ' ,  async  ( req ,  reply )  =>  { 
3530    return  twoByteUnicodeContent 
3631  } ) 
3732
38-   await  fastify . listen ( {  port : 0  } ) 
39- 
40-   const  {  port }  =  fastify . server . address ( ) 
41-   const  url  =  `http://localhost:${ port }  
33+   const  address  =  await  fastify . listen ( {  port : 0 ,  host : '127.0.0.1'  } ) 
4234
43-   const  response  =  await  request ( `${ url }  ) 
44-   const  response2  =  await  request ( `${ url }  ) 
45-   const  body  =  await  response . body . text ( ) 
46-   const  body2  =  await  response2 . body . text ( ) 
47-   t . equal ( body ,  body2 ) 
35+   const  response1  =  await  fetch ( `${ address }  ) 
36+   const  response2  =  await  fetch ( `${ address }  ) 
37+   const  body1  =  await  response1 . text ( ) 
38+   const  body2  =  await  response2 . text ( ) 
39+   t . equal ( body1 ,  body2 ) 
40+   t . equal ( body1 ,  twoByteUnicodeContent ) 
4841} ) 
0 commit comments