oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.09k stars 2.47k forks source link

Error using fastify.inject() to test a fastify web server #10894

Open fdaciuk opened 1 week ago

fdaciuk commented 1 week ago

What version of Bun is running?

1.1.7+b0b7db5c0

What platform is your computer?

Linux 6.6.30-1-MANJARO x86_64 unknown

What steps can reproduce the bug?

Create a new .js file, install fastify and run it:

import Fastify from "fastify"

const app = Fastify()

app.get("/hello", (_req, reply) => {
  reply.send("Hello World!")
})

async function test() {
  const result = await app.inject({
    method: "GET",
    url: "/hello"
  })

  console.log(result.payload)
}

test()

What is the expected behavior?

You should see the string "Hello World!"

What do you see instead?

This error:

177 |   response._lightMyRequest.headers = Object.assign({}, response.getHeaders())
178 |
179 |   // Add raw headers
180 |   ;['Date', 'Connection', 'Transfer-Encoding'].forEach((name) => {
181 |     const regex = new RegExp('\\r\\n' + name + ': ([^\\r]*)\\r\\n')
182 |     const field = response._header.match(regex)
                        ^
TypeError: undefined is not an object (evaluating 'response._header.match')
      at /code/fastify-inject/node_modules/light-my-request/lib/response.js:182:19
      at forEach (:1:21)
      at copyHeaders (/code/fastify-inject/node_modules/light-my-request/lib/response.js:180:4)
      at /code/fastify-inject/node_modules/light-my-request/lib/response.js:65:3
      at /code/fastify-inject/node_modules/fastify/lib/error-handler.js:42:9
      at fallbackErrorHandler (/code/fastify-inject/node_modules/fastify/lib/error-handler.js:127:3)
      at handleError (/code/fastify-inject/node_modules/fastify/lib/error-handler.js:34:5)
      at onErrorHook (/code/fastify-inject/node_modules/fastify/lib/reply.js:839:5)
      at /code/fastify-inject/node_modules/fastify/lib/reply.js:157:5
      at preValidationCallback (/code/fastify-inject/node_modules/fastify/lib/handleRequest.js:87:5)

Bun v1.1.7 (Linux x64)

Additional information

I'm using this API in production, but I can't test it without get a server up. In node.js it just works.