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 more tests (Part 1) #847

Merged
merged 6 commits into from
Jul 13, 2018
Merged

Conversation

endiliey
Copy link
Contributor

@endiliey endiliey commented Jul 11, 2018

Motivation

  1. We have lot of duplicate codes especially in server.js and generate.js
  2. We need to add more tests to catch regression
  3. Refactoring make it easier to migrate to Docusaurus v2

Changes

  1. Refactor duplicate mdToHtml function in server.js and generate.js
    https://github.com/facebook/Docusaurus/blob/a7a214fb3a36b3627e4346c2ddbcc4d01e3bf3a1/lib/server/generate.js#L108-L122
    https://github.com/facebook/Docusaurus/blob/a7a214fb3a36b3627e4346c2ddbcc4d01e3bf3a1/lib/server/server.js#L198-L212

  2. Move out core/routing.js to server/routing.js because it is more related to Express.js routing

  3. Refactor & Add tests for getLanguage and getSubDir in server/utils.js 😄

  4. Refactor duplicate isSeparateCss function in server.js and generate.js
    https://github.com/facebook/Docusaurus/blob/a7a214fb3a36b3627e4346c2ddbcc4d01e3bf3a1/lib/server/server.js#L118-L128
    https://github.com/facebook/Docusaurus/blob/a7a214fb3a36b3627e4346c2ddbcc4d01e3bf3a1/lib/server/generate.js#L74-L84

  5. Refactor duplicate insertTableOfContents function in server.js and generate.js to core/toc.js & add test for it
    https://github.com/facebook/Docusaurus/blob/a7a214fb3a36b3627e4346c2ddbcc4d01e3bf3a1/lib/server/generate.js#L60-L70
    https://github.com/facebook/Docusaurus/blob/a7a214fb3a36b3627e4346c2ddbcc4d01e3bf3a1/lib/server/server.js#L106-L116

  6. Moved core/getTOC.js function to core/toc.js so now core/toc.js has two functions:

  • getTOC
  • insertTOC

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  1. Test Locally
yarn start
  1. Test in netlify
    https://deploy-preview-847--docusaurus-preview.netlify.com/

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

docusaurus-bot commented Jul 11, 2018

Deploy preview for docusaurus-preview ready!

Built with commit 3ad88a7

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

@endiliey endiliey changed the title Refactor mdToHtml in dev & prod + add test Refactor server.js & generate.js Jul 12, 2018
@endiliey endiliey changed the title Refactor server.js & generate.js Refactor server code & add more tests Jul 12, 2018
@endiliey endiliey changed the title Refactor server code & add more tests Refactor + add more tests (Part 1) Jul 13, 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.

This is awesome @endiliey! Tests are great

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.

4 participants