Skip to content

Refactor + add more tests (Part 1)#847

Merged
yangshun merged 6 commits intofacebook:masterfrom
endiliey:mdtohtml
Jul 13, 2018
Merged

Refactor + add more tests (Part 1)#847
yangshun merged 6 commits intofacebook:masterfrom
endiliey:mdtohtml

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