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

refactor: add utility to identify non-standard ports #1616

Merged
merged 2 commits into from
Jul 13, 2019

Conversation

mastermatt
Copy link
Member

For #1404

We were doing this logic in several places and not always getting good coverage.
Adding a small utility DRYs it up.

For nock#1404

We were doing this logic in several places and not always getting good
coverage. Adding a small utility DRYs up the logic.
Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

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

Nice! One minor comment.

lib/common.js Outdated
port = `:${port}`
}
const { method = 'GET', path = '', port } = options
const portStr = addNonStandardPort(options.proto, port) ? `:${port}` : ''
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about moving the comma into the return value? I think it would clean these up a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

The colon?
Change the new function to always return a string? Either an empty string for the "false" case or :${port}.

Another option would be to require the host and return the host string, with the port if non standard.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes, the colon 😝

lib/recorder.js Outdated
scope.push(':')
scope.push(options.port)
if (common.addNonStandardPort(options.proto, options.port, options.host)) {
scope.push(':', options.port)
Copy link
Member

Choose a reason for hiding this comment

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

If you move the comma into the return value, the if statement can be removed.

@mastermatt
Copy link
Member Author

@paulmelnikow I expanded on your suggestion and changed it to return the whole origin since that's what all three callers were assembling anyway.

@paulmelnikow
Copy link
Member

This looks lovely!

Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

merge at your convenience 👍

@mastermatt mastermatt merged commit 7eef487 into nock:beta Jul 13, 2019
@mastermatt mastermatt deleted the non-standard-port-util branch July 13, 2019 02:40
@nockbot
Copy link
Collaborator

nockbot commented Jul 15, 2019

🎉 This PR is included in version 11.0.0-beta.24 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nockbot
Copy link
Collaborator

nockbot commented Aug 12, 2019

🎉 This PR is included in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this pull request Sep 4, 2019
For #1404 (code coverage)

We were doing this logic in several places and not always getting good
coverage. Adds a small utility DRY things up.
gr2m pushed a commit that referenced this pull request Sep 4, 2019
For #1404 (code coverage)

We were doing this logic in several places and not always getting good
coverage. Adds a small utility DRY things up.
gr2m pushed a commit that referenced this pull request Sep 5, 2019
For #1404 (code coverage)

We were doing this logic in several places and not always getting good
coverage. Adds a small utility DRY things up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants