-
Notifications
You must be signed in to change notification settings - Fork 2
test: unit test fails when using after msw 2.6.x #187
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
Conversation
test/utils.ts
Outdated
): SetupServer { | ||
const server = setupServer(...handlers) | ||
server.listen({ onUnhandledRequest: 'error' }) | ||
server.listen({ onUnhandledRequest: 'warn' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the new mswj version, setting onUnhandledRequest: 'error' throws an error for unhandled requests instead of doing nothing as before.
This change affects the test case for the ‘flush’ event.
To maintain the same test behavior as before, I switched it to just warn about unhandled requests.
@cre8ivejp what do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other options do we have?
Can we rewrite the test or use another tool to avoid working around it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is the options
"warn" (Default) | Print a warning but perform the request as-is. |
---|---|
"error" | Print an error and halt request execution. |
"bypass" | Does not print anything and perform the request as-is. |
======================
If we want to keep using the error
option, We could update the flush
test case @cre8ivejp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I restored the code be3d641
The unhandled request was created because the cross-fetch
was not working as expected.
We don't need to change any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
test/BKTClient.spec.ts
Outdated
FakeClock, | ||
} from './utils' | ||
import fetch from 'cross-fetch' | ||
// import fetch from 'cross-fetch' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cross-fetch
is outdated and isn't getting any update more than a years.
since Fetch is widely available (at least from Node.js 18 and higher).
so we could get rid of "cross-fetch" as a dependency.
I am testing more to make sure. So far all tests passed when run on both browser & node environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with node 18 and higher and it seems good.
mswjs example for vitest
could run on both browser & node environment without cross-fetch
https://github.com/mswjs/examples/tree/main/examples/with-vitest
[StrictRequest<GetEvaluationsRequest>], | ||
void | ||
>() | ||
const requestInterceptor = vi.fn((_request: StrictRequest<GetEvaluationsRequest>) => {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requestInterceptor should look like this with new mswjs version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🎉
I removed |
The commit 2099af0 addresses a test failure caused by an outdated & no longer maintain
cross-fetch
library and changes in themswjs
interface.E2e passed
https://github.com/bucketeer-io/javascript-client-sdk/actions/runs/11887259300