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

fix: live reload port fallback if port is used #899

Merged
merged 16 commits into from
Sep 12, 2018

Conversation

tom-auger
Copy link
Contributor

Motivation

Fixes #731

  1. Factored out the checking of an unused port to a separate module and use it when starting the Docusaurus server and the Live Reload server.
  2. Refactored the starting of servers into a separate module to enable testing.
  3. If the Live Reload server fails to start the Docusaurus server will still start but without live reload functionality.
  4. Added Jest tests for new modules.

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

  1. Added Jest tests around new code and checked they passed.
  2. Manually started multiple instances and checked the servers started on separate ports and the sites were accessible.

Related PRs

N/A

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 11, 2018
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Aug 11, 2018

Deploy preview for docusaurus-preview ready!

Built with commit febf0d5

https://deploy-preview-899--docusaurus-preview.netlify.com

Copy link
Contributor

@JoelMarcey JoelMarcey left a comment

Choose a reason for hiding this comment

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

@tom-auger I love that you did this.

In general, this looks overall better to me. I want a 2nd pair of eyes for confirmation.

@yangshun @endiliey 👋

@@ -0,0 +1,83 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ that you are adding tests.

module.exports = {
LIVE_RELOAD_PORT: 35729,
const tinylrServer = {
listen: jest.fn(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This file has no relationship to the constants file, right? You just changed the constants file and then made a file move. I am just wondering why GitHub thinks this is a file move.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, the two files are unrelated. I actually deleted the constants file in a separate commit, and added the tiny-lr mock in a later one, so I'm not sure why GitHub thinks this was a file move 😕

@endiliey endiliey self-assigned this Aug 22, 2018
Copy link
Contributor

@endiliey endiliey left a comment

Choose a reason for hiding this comment

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

Skimmed through it, seems ok for me.

Something to consider:

  1. Use https://www.npmjs.com/package/portfinder instead of building our own. But this PR's findUnusedPort looks OK to me
  2. I think lib/serverController.js should be named lib/server/start or at least moved to lib/server folder since ideally we want all the docusaurus-<command> to be on lib folder and not others

@endiliey endiliey removed their assignment Aug 23, 2018
@endiliey endiliey requested a review from yangshun August 23, 2018 07:25
@endiliey endiliey changed the title Try new live reload port if default is in use fix: live reload port fallback if port is used Aug 23, 2018
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

@tom-auger This is awesome! I think the tests are quite overkill since this is a non-essential feature and pretty simple to test. But I absolutely love that you're adding them. Do you have time to respond to the comments by @endiliey? If not I think we could fix it for you and merge it. Let us know 😄

@tom-auger
Copy link
Contributor Author

@yangshun thanks 😃, sure I can fix it up! RE the comments by @endiliey:

  1. The node-portfinder package looks simple to drop in as a replacement to my findUnusedPort implementation. I'm happy to do that if you think it's better?
  2. Will rename and move serverController.js as suggested.
  3. Do you want to keep any of the tests I've added? I don't mind removing some or all of them if you don't need them 😃

@tom-auger
Copy link
Contributor Author

@yangshun I've made the suggested changes. I fixed the tests too, but if you don't want to keep them feel free to remove them 😄

Copy link
Contributor

@endiliey endiliey left a comment

Choose a reason for hiding this comment

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

LGTM.

Amazed that you were able to add the test 😭

@endiliey endiliey merged commit bbef20d into facebook:master Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants