fastify / fastify-nextjs

React server side rendering support for Fastify with Next
Other
532 stars 61 forks source link

fastify.inject timeout when @fastify/nextjs is registered #748

Open joshuaavalon opened 1 year ago

joshuaavalon commented 1 year ago

Prerequisites

Fastify version

4.17.0

Plugin version

9.2.0

Node.js version

v20.1.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

10

Description

When I run unit tests by fastify.inject, it timeout after several requests.

- event compiled client and server successfully in 639 ms (151 modules)
      1) should create user with admin role
- event compiled client and server successfully in 311 ms (151 modules)
      ✔ should create normal user (1291ms)
    login
      2) should login admin user
      3) should login normal user
    me
      4) should return admin user
      5) should return normal user

  1 passing (11s)
  5 failing

  1) User
       createUser
         should create user with admin role:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\user\project\git\api2\dist\__tests__\index.js)
      at listOnTimeout (node:internal/timers:573:17)
      at process.processTimers (node:internal/timers:514:7)

Steps to Reproduce

I run test with the following

server.inject({
  method: "POST",
  url: "/graphql",
  payload: { query: print(documentNode), variables },
  headers: authToken
    ? { authorization: `Bearer ${authToken}` }
    : undefined
});

Expected Behavior

The tests do not timeout

mcollina commented 1 year ago

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

joshuaavalon commented 1 year ago

Example: https://github.com/joshuaavalon/fastify-nextjs-bug

  1. npm i
  2. npm run start

Expect the script to stop after 1 is print, however, it does not stop.

The expected behavior is what commenting out await app.register(nextPlugin); in index.js.

mcollina commented 1 year ago

Apparently we have not tests using inject(), so it's likely possible this would never work or it would not be possible to make it work.

https://github.com/fastify/fastify-nextjs/blob/master/test/index.test.js

joshuaavalon commented 1 year ago

My current workaround is just to not register this plugin when using inject.