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(client): refactor createSocketUrl to make it better unit tested #2336

Merged

Conversation

nougad
Copy link
Contributor

@nougad nougad commented Nov 29, 2019

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

Motivation / Use-Case

Follow up from #2303 to add more tests

// strip leading `?` from query string to get a valid URL
.substr(1)
// replace first `&` with `?` to have a valid query string
.replace('&', '?'),
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The full URL is something like http://example.com/?http://0.0.0.0:8096&sockPort=8097&sockHost=localhost while this method only gets the path: ?http://0.0.0.0:8096&sockPort=8097&sockHost=localhost

This will convert the path into a full url by 1) removing the leading ? and 2) replace the first & with a ?. The result is a valid URL which can be parsed: url.parse('http://0.0.0.0:8096?sockPort=8097&sockHost=localhost')

The removal of the leading ? was already done before. The difference is the replace of & to get a valid URL. That allows to use urlParts.query instead of before querystring.parse(urlParts.path).

I agree the parsing and replacement is a bit funky but I also don't get why the parameter is a invalid url instead of just passing the host as a normal query parameter.

Copy link
Member

Choose a reason for hiding this comment

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

@nougad what about(rewrite) fix it in other PRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to fix this because the actual problem comes from a problematic protocol to signal the sock endpoint. I don't think I have enough knowledge about the details to change the protocol.

} else {
// Else, get the url from the <script> this file was called with.
const scriptHost = getCurrentScriptSource();
urlParts = url.parse(scriptHost || '/', false, true);
urlParts = url.parse(scriptHost || '/', true, true);
Copy link
Member

Choose a reason for hiding this comment

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

Why we need parse query string here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is related to the comment above. Having a full URL including parsed query string saves from another querystring.parse(urlParts.path) later on.

@codecov
Copy link

codecov bot commented Nov 29, 2019

Codecov Report

Merging #2336 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2336      +/-   ##
==========================================
+ Coverage   93.88%   93.94%   +0.06%     
==========================================
  Files          34       34              
  Lines        1291     1289       -2     
  Branches      368      367       -1     
==========================================
- Hits         1212     1211       -1     
+ Misses         78       77       -1     
  Partials        1        1
Impacted Files Coverage Δ
client-src/default/utils/createSocketUrl.js 100% <100%> (+3.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f8c575...d21fd96. Read the comment docs.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Good job!

/cc @hiroppy @Loonride can you look at this?

@alexander-akait alexander-akait merged commit a599f99 into webpack:master Dec 5, 2019
@alexander-akait
Copy link
Member

Thanks!

@nougad nougad deleted the refactor-createsocketurl-tests branch December 5, 2019 12:45
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

4 participants