-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor + add more tests (Part 1) (#847)
* Refactor mdToHtml out * Refactor routing + move it to server instead of core * Refactor & Add more tests for server utils * Refactor isSeparateCss function from server & generate * Refactor insertTableOfContents from server & generate + add tests * undo small nits
- Loading branch information
Showing
14 changed files
with
322 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
id: pokemon-commands | ||
title: Pokemon Commands | ||
--- | ||
|
||
## Commands | ||
|
||
<AUTOGENERATED_TABLE_OF_CONTENTS> | ||
|
||
--- | ||
|
||
## Reference | ||
|
||
### `pokemon-run` | ||
|
||
Alias: `run`. | ||
|
||
### `pokemon-fight` | ||
|
||
Alias: `fight` | ||
|
||
### `pokemon-bag` | ||
|
||
Alias: `bag` | ||
|
||
### `pokemon-rename` | ||
|
||
Alias: `rename` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const path = require('path'); | ||
const readFileSync = require('fs').readFileSync; | ||
const {getTOC, insertTOC} = require('../toc'); | ||
const {extractMetadata} = require('../../server/metadataUtils'); | ||
|
||
const getTOCmd = readFileSync( | ||
path.join(__dirname, '__fixtures__', 'getTOC.md'), | ||
'utf8' | ||
); | ||
|
||
const insertTOCmd = readFileSync( | ||
path.join(__dirname, '__fixtures__', 'insertTOC.md'), | ||
'utf8' | ||
); | ||
|
||
describe('getTOC', () => { | ||
test('with defaults', () => { | ||
const headings = getTOC(getTOCmd); | ||
const headingsJson = JSON.stringify(headings); | ||
|
||
expect(headings).toMatchSnapshot(); | ||
expect(headingsJson).toContain('bar-8'); // maximum unique bar index is 8 | ||
expect(headingsJson).not.toContain('4th level headings'); | ||
}); | ||
|
||
test('with custom heading levels', () => { | ||
const headings = getTOC(getTOCmd, 'h2', ['h3', 'h4']); | ||
const headingsJson = JSON.stringify(headings); | ||
|
||
expect(headings).toMatchSnapshot(); | ||
expect(headingsJson).toContain('bar-8'); // maximum unique bar index is 8 | ||
expect(headingsJson).toContain('4th level headings'); | ||
}); | ||
}); | ||
|
||
describe('insertTOC', () => { | ||
test('null or undefined content', () => { | ||
expect(insertTOC(null)).toBeNull(); | ||
expect(insertTOC(undefined)).toBeUndefined(); | ||
}); | ||
|
||
test('AUTOGENERATED_TABLE_OF_CONTENTS does not exist', () => { | ||
const rawContent = extractMetadata(getTOCmd).rawContent; | ||
expect(insertTOC(rawContent)).toMatchSnapshot(); | ||
expect(insertTOC(rawContent)).toEqual(rawContent); | ||
}); | ||
|
||
test('AUTOGENERATED_TABLE_OF_CONTENTS exists', () => { | ||
const rawContent = extractMetadata(insertTOCmd).rawContent; | ||
expect(insertTOC(rawContent)).toMatchSnapshot(); | ||
expect(insertTOC(rawContent)).not.toEqual(rawContent); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.