Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with native fetch introduce after 0.25.1? #574

Open
lox opened this issue May 20, 2024 · 2 comments
Open

Issue with native fetch introduce after 0.25.1? #574

lox opened this issue May 20, 2024 · 2 comments

Comments

@lox
Copy link

lox commented May 20, 2024

I have been trying to upgrade to the latest 0.29.1 from 0.25.1 and running into a variety of issues that I am trying to isolate down top the smallest repros that I can. This is the first oddity I have encountered.

Running:

@mswjs/interceptors 0.25.1
node v20.5.1
import { FetchInterceptor } from '@mswjs/interceptors/fetch'
import http from 'http'

const interceptor = new FetchInterceptor()
interceptor.apply()

interceptor.on('request', ({ request, requestId }) => {
  request.respondWith(
    new Response('Intercepted', {
      status: 200,
      statusText: 'OK',
    })
  )
})

const server = http.createServer((req, res) => {
  res.statusCode = 200
  res.setHeader('Content-Type', 'text/plain')
  res.end('hello world')
})

server.listen(3000, '127.0.0.1', () => {
  console.log('Server running at http://127.0.0.1:3000/')
})

const response = await fetch('http://localhost:3000/', {
  method: 'GET',
})

console.log(await response.text())

interceptor.dispose()
server.close()

On 0.25.1 this returned:

❯ node scripts/testHttpIntercept.js
Server running at http://127.0.0.1:3000/
Intercepted

On 0.29.1 this runs, but hangs on:

❯ node scripts/testHttpIntercept.js
Intercepted
Server running at http://127.0.0.1:3000/

Am I missing something very basic here?

@lox
Copy link
Author

lox commented May 20, 2024

I've tested and this works as expected up to v0.28.4, it breaks in https://github.com/mswjs/interceptors/releases/tag/v0.29.0

@kettanaito
Copy link
Member

Please also make sure to update Undici to the latest version. There were bugs that broke your code in unapparent ways.

I will take a look at this once I have a minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants