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

Feat/ws sync handlers #2028

Open
wants to merge 223 commits into
base: main
Choose a base branch
from
Open

Conversation

chrisb2244
Copy link

@chrisb2244 chrisb2244 commented Feb 9, 2024

Possible implementation for the feat/ws-sync-handlers branch.

A new dummyResponse is sent by the remote handler when the request is not handled by the remote handler - this allows the calling code (via executeHandlers) to identify that the request was not handled (even though it has been '(not-)handled' by the remote handler).

It's very possible I used the wrong commit tags/types, so am happy to rewrite them as required.

The remotePort is set to a static value here - guidance on how you'd prefer this to be set would be welcome (and I can rebase as needed before merging) - however, I wasn't sure the current intention because the remote flag mentioned in part of the upstream draft PR seems to have changed to the remotePort value, and its existence is used to determine remoteness (so defaulting seems like it would cause problems).
If the intent is for the user to specify a port (static or potentially via environment variable, but within their code) then I think leaving a static value in the tests is perhaps(?) acceptable.

I'll add a comment to part of the changed code with further questions/thoughts on an alternative in case it isn't what/where you wanted changes.

src/node/SetupServerApi.ts Outdated Show resolved Hide resolved
src/node/SetupServerApi.ts Outdated Show resolved Hide resolved
src/node/SetupServerApi.ts Outdated Show resolved Hide resolved
Can achieve same result by simply returning early, then use the as-previously-defined handling for the general case.
Add a dummy response to trigger the unhandled response in the collection of handlers for the non-remote setupServer-produced Server.
This allows an unhandledRequest to exist, despite the remoteHandler always being triggered if added.
@chrisb2244 chrisb2244 marked this pull request as ready for review February 13, 2024 08:18
Comment on lines 79 to 85
remoteResolutionUrl.pathname = '/socket.io'
const matcher = new RegExp(`${remoteResolutionUrl.href}/.*`)
const isRequestForSocket = matcher.test(request.url)
// Bypass handling if the request is for the socket.io connection
if (isRequestForSocket) {
return
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pathname here depends on socket-io's default value, because MSW doesn't set the value in opts.path (see setupRemoteServer.ts, line 210, second arg).
If you preferred, then that location could be changed to set the path, and then this wouldn't be dependent on their potential changes to default values.

@chrisb2244
Copy link
Author

I'm not sure if retargeting this to main rather than feat/ws-sync-handlers will clear up a lot of the commits (most are from merging v2.2.0).

…e port

This fixes a test that was broken by the previous commit, which checked the behaviour of listHandlers().
This prevents repeatedly triggering disconnects and incorrectly resetting handlers
@chrisb2244 chrisb2244 changed the base branch from feat/ws-sync-handlers to main February 15, 2024 02:14
@chrisb2244
Copy link
Author

I'm not quite sure how to fix the CI checks here - it seems to be complaining about indentation in a file that I guess was changed in main between where the msw/feat/ws-sync-handlers branch started (which I used as the upstream branch to start) and now?

I tried resaving the file (which gave two extra spaces via prettier) but that didn't change the outcome of the action check as far as I can tell.

@chrisb2244 chrisb2244 changed the base branch from main to run-test-variants-in-parallel February 15, 2024 07:49
@chrisb2244 chrisb2244 changed the base branch from run-test-variants-in-parallel to main February 15, 2024 07:49
@chrisb2244
Copy link
Author

#2041 is a much cleaner (although arguably more fake) set of commits to the same destination, and may be easier to review/merge if desired.

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 this pull request may close these issues.

None yet

8 participants