bun icon indicating copy to clipboard operation
bun copied to clipboard

Koa server returns `Welcome to Bun! To get started, return a Response object.` on test env

Open nicreichert opened this issue 9 months ago • 1 comments

What version of Bun is running?

1.0.25+a8ff7be64

What platform is your computer?

Darwin 22.5.0 x86_64 i386

What steps can reproduce the bug?

This issue happens only when testing my application, so, I can't really share a reproducible code, however, the behaviour is as follows:

I have a monorepo with FE + BE. The BE is using koa, and in dev and prod everything works perfectly fine. I have a package that handles the requests to the server and is used by FE. However, I'm using this same package to make requests in my server's unit tests. It's using fetch, and, when fetching, the response for all requests (again, only on test env) is always the text Welcome to Bun! To get started, return a Response object.

I checked the controllers and everything is correct there, meaning the controller changes the context.body of the requests correctly, and yet, the responses have no body, just the text.

What is the expected behavior?

I expect my JSON to be sent on the body of the responses.

What do you see instead?

Welcome to Bun! To get started, return a Response object.

Additional information

My tests setup use happy-dom, so, I added the following snippet for setup:

import { GlobalRegistrator } from '@happy-dom/global-registrator'

const bunFetch = fetch
GlobalRegistrator.register()
window.fetch = bunFetch

I got this snippet from this issue

nicreichert avatar May 03 '24 09:05 nicreichert

I'm facing the same issue when node is not installed. Installing node fixes the problem I'm having with running remix via bun. Reproduces on minimal setup.

  • bunx create-remix@latest
  • bun run dev

Not sure how to feel about it. Leaving this here in case someone finds it useful

vv3rd avatar May 11 '24 15:05 vv3rd