capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.14k stars 189 forks source link

`GlobalRegistrator.register()` should omit the `Response` class #1480

Open jackens opened 3 weeks ago

jackens commented 3 weeks ago

Describe the bug

GlobalRegistrator.register() processes the Response class, causing Bun.serve to not work in bun:test mode

To Reproduce

bug.test.ts:

import { file, serve } from 'bun'
import { execSync } from 'child_process'
import { join } from 'path'

const server = serve({
  port: 12345,
  fetch ({ url }) {
    return new Response(file(join('.', new URL(url).pathname)))
  }
})

execSync('open http://127.0.0.1:12345/index.html')

await new Promise(resolve => setTimeout(resolve, 3_000))

server.stop()

index.html:

<!doctype html>
<html lang="en">
<head><meta charset="UTF-8" /></head>
<body>The content of the ‘index.html’ file is irrelevant…</body>
</html>

bunfig.toml:

[test]
preload = "./test/happy-dom.ts"

./test/happy-dom.ts:

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

GlobalRegistrator.register()

The execution of bun bug.test.ts works OK, but executing bun test bug.test.ts causes an error (see attached screenshot).

Expected behavior

GlobalRegistrator.register() should omit the Response class

Screenshots

bug

Device:

Additional context

Cf. https://github.com/oven-sh/bun/issues/12408