-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Better anchors navigation with unique slugs (#318)
* Fixes anchors for sections with multiple words in name * Fixes the case when components or sections with same name could not be resolved by anchor * Adds anchor navigation to the tittle of section/component * Use `<section>` tag for sections * Use `describe` in utils tests * Use only react-docgen-displayname-handler to read component name * Do not try to detect component name at runtime * Remove nameFallback * Put examples inside props * Pass actual component name to default example instead of fallback * Explicitly support only one component in props-loader BREAKING CHANGE: handlers config option is now function instead of array.
- Loading branch information
Showing
46 changed files
with
823 additions
and
360 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
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 |
---|---|---|
@@ -1,28 +1,47 @@ | ||
import vm from 'vm'; | ||
import { readFileSync } from 'fs'; | ||
import config from '../../scripts/schemas/config'; | ||
import propsLoader from '../props-loader'; | ||
|
||
const _styleguidist = { | ||
handlers: config.handlers.default, | ||
getExampleFilename: config.getExampleFilename.default, | ||
}; | ||
|
||
it('should return valid, parsable JS', () => { | ||
const file = './test/components/Button/Button.js'; | ||
const result = propsLoader.call({ | ||
request: file, | ||
_styleguidist: {}, | ||
_styleguidist, | ||
}, readFileSync(file, 'utf8')); | ||
expect(result).toBeTruthy(); | ||
expect(() => new Function(result)).not.toThrowError(SyntaxError); // eslint-disable-line no-new-func | ||
expect(new vm.Script(result)).not.toThrowError(SyntaxError); | ||
}); | ||
|
||
it('should extract doclets', () => { | ||
const file = './test/components/Placeholder/Placeholder.js'; | ||
const result = propsLoader.call({ | ||
request: file, | ||
_styleguidist: {}, | ||
_styleguidist, | ||
}, readFileSync(file, 'utf8')); | ||
expect(result).toBeTruthy(); | ||
|
||
expect(() => new Function(result)).not.toThrowError(SyntaxError); // eslint-disable-line no-new-func | ||
expect(result.includes('getImageUrl')).toBe(true); | ||
expect(new vm.Script(result)).not.toThrowError(SyntaxError); | ||
expect(result.includes('makeABarrelRoll')).toBe(false); | ||
expect(result).toMatch('getImageUrl'); | ||
expect(result).toMatch(/'see': '\{@link link\}'/); | ||
expect(result).toMatch(/'link': 'link'/); | ||
expect(result).toMatch(/require\('!!.*?\/loaders\/examples-loader\.js!\.\/examples.md'\)/); | ||
}); | ||
|
||
it('should attach examples from Markdown file', () => { | ||
const file = './test/components/Button/Button.js'; | ||
const result = propsLoader.call({ | ||
request: file, | ||
_styleguidist, | ||
}, readFileSync(file, 'utf8')); | ||
expect(result).toBeTruthy(); | ||
|
||
expect(new vm.Script(result)).not.toThrowError(SyntaxError); | ||
expect(result).toMatch(/require\('!!.*?\/loaders\/examples-loader\.js!test\/components\/Button\/Readme.md'\)/); | ||
}); |
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
4 changes: 2 additions & 2 deletions
4
loaders/utils/__tests__/__snapshots__/getAllComponentsWithExamples.spec.js.snap
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
exports[`test should return only components with example file 1`] = ` | ||
Array [ | ||
Object { | ||
"examples": "require()", | ||
"filepath": "components/Button/Button.js", | ||
"hasExamples": true, | ||
}, | ||
Object { | ||
"examples": "require()", | ||
"filepath": "components/Modal/Modal.js", | ||
"hasExamples": true, | ||
}, | ||
] | ||
`; |
6 changes: 2 additions & 4 deletions
6
loaders/utils/__tests__/__snapshots__/getComponents.spec.js.snap
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
5 changes: 1 addition & 4 deletions
5
loaders/utils/__tests__/__snapshots__/processComponent.spec.js.snap
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.