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

Fetch does not await of the response listener #656

Closed
mikicho opened this issue Oct 5, 2024 · 2 comments · Fixed by #658
Closed

Fetch does not await of the response listener #656

mikicho opened this issue Oct 5, 2024 · 2 comments · Fixed by #658
Assignees

Comments

@mikicho
Copy link
Contributor

mikicho commented Oct 5, 2024

Following this change, we need to update the behavior for fetch as well.

const { FetchInterceptor } = require('@mswjs/interceptors/fetch')

const interceptor = new FetchInterceptor({
  name: 'my-interceptor',
})
interceptor.apply();
interceptor.on('response', async ({ request }) => {
  await new Promise(r => setTimeout(r, 100));
  console.log(2);
});

(async function () {
  console.log(1);
  await fetch('http://example.com')
  console.log(3);
})()

Actual:

1
3
2

Expected:

1
2
3

@kettanaito I believe I can make this change, but I want to ensure that there are no unintended side effects that I haven't considered with this change.

@kettanaito
Copy link
Member

Hi, @mikicho. That actual order doesn't seem right. Go ahead to open a pull request to fix this 👍 I will take a look how we are handling this in MockHttpSocket during the review to make sure we stay consistent.

@kettanaito
Copy link
Member

Released: v0.36.4 🎉

This has been released in v0.36.4!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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

Successfully merging a pull request may close this issue.

2 participants