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

Intercepted fetch results in the the process never exiting / hangs Mocha tests #491

Open
vassudanagunta opened this issue Dec 9, 2023 · 0 comments

Comments

@vassudanagunta
Copy link

I'm new to mswjs. I tried to use FetchInterceptor in a Mocha test, and the test would always hang indefinitely, with no console output, until I hit CTRL-C in the terminal (SIGINT), at which point all the console output suddenly dumbs and the test reports success or fail and other tests continue. The console output showed two things: Everything ran to completion, and did so immediately based on the timestamps printed in the console log.

To isolate this and eliminate Mocha as a culprit, I created the following script:

import {FetchInterceptor} from '@mswjs/interceptors/fetch'

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

const requestURL = 'https://raw.githubusercontent.com/vassudanagunta/htmlnorm/main/README.md'

console.log('before fetch', new Date().toISOString())

const resp = await fetch(requestURL)
console.log('after fetch', new Date().toISOString())
console.log('fetched', resp)

interceptor.dispose()
console.log('after dispose', new Date().toISOString())

executing node <path to above script> results in everything running as expected all they way to the last console write, but the process doesn't exit. Not until a SIGINT.

Commenting out either interceptor.apply() or const resp = await fetch(requestURL) eliminates the hang. The script is so simple, I can't imagine what I am doing wrong.


Node v21.4.0
@mswjs/interceptors v0.25.13

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

1 participant