-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Addon-docs: Snapshot testing and bug reporting for props tables #9838
Merged
Merged
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
61545c3
Addon-docs: React properties snapshot testing
shilman 4e73945
Addon-docs: Document prop tables bug reporting and known limitations
shilman 8297083
Merge branch 'next' into 9690-component-properites
shilman 676a597
Merge branch 'next' into 9690-component-properites
shilman 90b97a5
Fix typo
shilman 92bfc1a
Addon-docs: Angular properties snapshot testing POC
shilman 659dc82
Cleanup :joy:
shilman eeab514
Addon-docs: Cleanup angular properties tests
shilman ed4b831
Addon-docs: Web-components properties tests
shilman 8063b52
Props: #9399 repro test
shilman 14456b2
Props: #8663 repro
shilman 3cfe6e1
Props: #9626 repro
shilman b467fa8
Addon-docs: React props extraction stories
shilman 8219af1
Props: #9668 attempted repro
shilman e3927d9
Props: #8143 repro
shilman 4129773
Props: #8143 repro for imported types
shilman eaa147a
Props: #8279 repro
shilman 964d40d
Props: #8180 repro
shilman e3ab757
Props: #9023 repro
shilman 85e4f6d
Props: #8740 repro
shilman 822f3df
Props: #8894 forward-ref repro
shilman 92f8c43
Props: #9556 repro
shilman c8c19a2
Props: #9592 styled repro
shilman 82ee3a3
Props: #9591 repro
shilman 94a8ae7
Props: #9721 repro
shilman 3e90384
Props: #9832 repro
shilman 05f44c1
Props: #9827 repro
shilman ee4144a
Props: #9586 repro
shilman 03a2693
Props: #9575 repro
shilman ed714ba
Props: #9493 repro
shilman 57e571c
Props: #9493 update snapshots
shilman 1032b77
Props: #9511 repro
shilman dd10817
Props: #9465 repro
shilman 28f7a7e
Props: #8428 repro
shilman 249de2c
Update docgen.snapshot
shilman ce8a9f2
Props: #9764 repro
shilman 5d942d1
Props: Fix crash on 9399-js-proptypes-shape
shilman 62de2a6
Props: Fix test typings
shilman b64e3cf
Addon-docs: Fix props tests
shilman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,97 @@ | ||
<center> | ||
<img src="./media/props-tables-hero.png" width="100%" /> | ||
</center> | ||
|
||
<h1>Storybook Docs Props Tables</h1> | ||
|
||
Storybook Docs automatically generates props tables for components in supported frameworks. This document is a consolidated summary of prop tables, provides instructions for reporting bugs, and list known limitations for each framework. | ||
|
||
- [Usage](#usage) | ||
- [Reporting a bug](#reporting-a-bug) | ||
- [Known limitations](#known-limitations) | ||
- [React](#react) | ||
- [Vue](#vue) | ||
- [Angular](#angular) | ||
- [Web components](#web-components) | ||
- [Ember](#ember) | ||
- [More resources](#more-resources) | ||
|
||
## Usage | ||
|
||
For framework-specific setup instructions, see the framework's README: [React](../../react/README.md), [Vue](../../vue/README.md), [Angular](../../angular/README.md), [Web Components](../../web-components/README.md), [Ember](../../ember/README.md). | ||
|
||
To use the props table in [DocsPage](./docspage.md), simply export a component property on your stories metadata: | ||
|
||
```js | ||
// MyComponent.stories.js | ||
import { MyComponent } from './MyComponent'; | ||
|
||
export default { | ||
title: 'MyComponent', | ||
component: MyComponent, | ||
}; | ||
// stories etc... | ||
``` | ||
|
||
To use the props table in [MDX](./mdx.md), use the `Props` block: | ||
|
||
```js | ||
// MyComponent.stories.mdx | ||
import { Props } from '@storybook/addon-docs/blocks'; | ||
import { MyComponent } from './MyComponent'; | ||
|
||
# My Component! | ||
|
||
<Props of={MyComponent} /> | ||
``` | ||
|
||
## Reporting a bug | ||
|
||
Extracting component properties from source is a tricky problem with thousands of corner cases. We've designed this package and its tests to accurately isolate problems, since the cause could either be in this package or (likely) one of the packages it depends on. | ||
|
||
If you're seeing a problem with your prop table, here's what to do. | ||
|
||
First, look to see if there's already a test case that corresponds to your situation. If there is, it should be documented in the [Known Limitations](#known-limitations) section above. There should also be one or more corresponding test fixtures contained in this package. For example, if you are using React, look under the directory `./src/frameworks/react/__testfixtures__`. | ||
|
||
If your problem is not already represented here, do the following: | ||
|
||
1. Create a **MINIMAL** repro for your problem. Each case should be just a few lines of code. | ||
2. Place it in the appropriate directory `./src/<framework>/__testfixtures__/`, e.g. `./src/react/__testfixtures__/XXXX-some-description`, where `XXXX` is the corresponding github issue. | ||
3. Run the tests for your `<framework>`, e.g. `yarn jest --testPathPattern=react-properties.test.ts --watch` | ||
4. Inspect the output files for your test case. | ||
5. Add the example to the appropriate stories file, e.g. `react-properties.stories.ts` for `react`, for a visual repro | ||
|
||
If the problem appears to be an issue with this library, file an issue and include a PR that includes your repro. | ||
|
||
If the problem appears to be an issue with the sub-package, please file an issue on the appropriate sub-package, document the limitation in [Known Limitations](#known-limitations) below, link to that issue, and submit a PR including the updated documentation and fixtures/snapshots. | ||
|
||
## Known limitations | ||
|
||
This package relies on a variety of sub-packages to extract property information from components. Many of the bugs in this package correspond to bugs in a sub-package. Since we don't maintain the sub-packages, the best we can do for now is (1) document these limitations, (2) provide clean reproductions to the sub-package, (3) optionally provide PRs to those packages to fix the problems. | ||
|
||
### React | ||
|
||
SB Docs for React uses `babel-plugin-react-docgen`/`react-docgen` for both JS PropTypes prop tables and, as of 6.0, TypeScript-driven props tables. | ||
|
||
### Vue | ||
|
||
SB Docs for Vue uses `vue-docgen-loader`/`vue-docgen-api` for SFC and JSX components. | ||
|
||
### Angular | ||
|
||
SB Docs for Angular uses `compodoc` for prop table information. | ||
|
||
### Web components | ||
|
||
SB Docs for Web-components uses `custom-elements.json` for prop table information. | ||
|
||
### Ember | ||
|
||
SB Docs for Ember uses `yui-doc` for prop table information. | ||
|
||
## More resources | ||
|
||
- References: [README](../README.md) / [DocsPage](docspage.md) / [MDX](mdx.md) / [FAQ](faq.md) / [Recipes](recipes.md) / [Theming](theming.md) | ||
- Framework-specific docs: [React](../react/README.md) / [Vue](../vue/README.md) / [Angular](../angular/README.md) / [Web components](../web-components/README.md) / [Ember](../ember/README.md) | ||
- Announcements: [Vision](https://medium.com/storybookjs/storybook-docs-sneak-peak-5be78445094a) / [DocsPage](https://medium.com/storybookjs/storybook-docspage-e185bc3622bf) / [MDX](https://medium.com/storybookjs/rich-docs-with-storybook-mdx-61bc145ae7bc) / [Framework support](https://medium.com/storybookjs/storybook-docs-for-new-frameworks-b1f6090ee0ea) | ||
- Example: [Storybook Design System](https://github.com/storybookjs/design-system) |
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
45 changes: 45 additions & 0 deletions
45
addons/docs/src/frameworks/react/__testfixtures__/js-class-component/docgen.snapshot
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,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`react component properties js-class-component 1`] = ` | ||
"/* eslint-disable react/prefer-stateless-function */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
/** | ||
* Component description | ||
*/ | ||
|
||
class ErrorBox extends React.Component { | ||
render() { | ||
const { | ||
children | ||
} = this.props; | ||
return React.createElement(\\"div\\", { | ||
className: \\"error-box\\" | ||
}, children); | ||
} | ||
|
||
} | ||
|
||
ErrorBox.propTypes = { | ||
/** | ||
* PropTypes description | ||
*/ | ||
children: PropTypes.node.isRequired | ||
}; | ||
ErrorBox.__docgenInfo = { | ||
\\"description\\": \\"Component description\\", | ||
\\"methods\\": [], | ||
\\"displayName\\": \\"ErrorBox\\", | ||
\\"props\\": { | ||
\\"children\\": { | ||
\\"type\\": { | ||
\\"name\\": \\"node\\" | ||
}, | ||
\\"required\\": true, | ||
\\"description\\": \\"PropTypes description\\" | ||
} | ||
} | ||
}; | ||
export default ErrorBox; | ||
export const component = ErrorBox;" | ||
`; |
24 changes: 24 additions & 0 deletions
24
addons/docs/src/frameworks/react/__testfixtures__/js-class-component/input.js
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,24 @@ | ||
/* eslint-disable react/prefer-stateless-function */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Component description | ||
*/ | ||
class ErrorBox extends React.Component { | ||
render() { | ||
const { children } = this.props; | ||
|
||
return <div className="error-box">{children}</div>; | ||
} | ||
} | ||
|
||
ErrorBox.propTypes = { | ||
/** | ||
* PropTypes description | ||
*/ | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
export default ErrorBox; | ||
export const component = ErrorBox; |
18 changes: 18 additions & 0 deletions
18
addons/docs/src/frameworks/react/__testfixtures__/js-class-component/properties.snapshot
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,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`react component properties js-class-component 1`] = ` | ||
Object { | ||
"rows": Array [ | ||
Object { | ||
"defaultValue": null, | ||
"description": "PropTypes description", | ||
"name": "children", | ||
"required": true, | ||
"type": Object { | ||
"detail": undefined, | ||
"summary": "node", | ||
}, | ||
}, | ||
], | ||
} | ||
`; |
64 changes: 64 additions & 0 deletions
64
addons/docs/src/frameworks/react/__testfixtures__/ts-function-component/docgen.snapshot
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,64 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`react component properties ts-function-component 1`] = ` | ||
"import React from 'react'; | ||
|
||
/** | ||
* The world's most _basic_ button | ||
*/ | ||
export const Button = ({ | ||
onClick | ||
}) => React.createElement(\\"button\\", { | ||
onClick: onClick, | ||
type: \\"button\\" | ||
}, \\"hello\\"); | ||
Button.defaultProps = { | ||
primary: true, | ||
secondary: false | ||
}; | ||
export const component = Button; | ||
Button.__docgenInfo = { | ||
\\"description\\": \\"The world's most _basic_ button\\", | ||
\\"methods\\": [], | ||
\\"displayName\\": \\"Button\\", | ||
\\"props\\": { | ||
\\"primary\\": { | ||
\\"defaultValue\\": { | ||
\\"value\\": \\"true\\", | ||
\\"computed\\": false | ||
}, | ||
\\"required\\": false, | ||
\\"tsType\\": { | ||
\\"name\\": \\"boolean\\" | ||
}, | ||
\\"description\\": \\"Is primary?\\" | ||
}, | ||
\\"secondary\\": { | ||
\\"defaultValue\\": { | ||
\\"value\\": \\"false\\", | ||
\\"computed\\": false | ||
}, | ||
\\"required\\": false, | ||
\\"tsType\\": { | ||
\\"name\\": \\"boolean\\" | ||
}, | ||
\\"description\\": \\"default is false\\" | ||
}, | ||
\\"onClick\\": { | ||
\\"required\\": false, | ||
\\"tsType\\": { | ||
\\"name\\": \\"signature\\", | ||
\\"type\\": \\"function\\", | ||
\\"raw\\": \\"() => void\\", | ||
\\"signature\\": { | ||
\\"arguments\\": [], | ||
\\"return\\": { | ||
\\"name\\": \\"void\\" | ||
} | ||
} | ||
}, | ||
\\"description\\": \\"Simple click handler\\" | ||
} | ||
} | ||
};" | ||
`; |
34 changes: 34 additions & 0 deletions
34
addons/docs/src/frameworks/react/__testfixtures__/ts-function-component/input.tsx
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,34 @@ | ||
import React, { FC } from 'react'; | ||
|
||
interface ButtonProps { | ||
/** | ||
* Simple click handler | ||
*/ | ||
onClick?: () => void; | ||
|
||
/** | ||
* Is primary? | ||
*/ | ||
primary?: boolean; | ||
|
||
/** | ||
* default is false | ||
*/ | ||
secondary?: boolean; | ||
} | ||
|
||
/** | ||
* The world's most _basic_ button | ||
*/ | ||
export const Button: React.FC<ButtonProps> = ({ onClick }: ButtonProps) => ( | ||
<button onClick={onClick} type="button"> | ||
hello | ||
</button> | ||
); | ||
|
||
Button.defaultProps = { | ||
primary: true, | ||
secondary: false, | ||
}; | ||
|
||
export const component = Button; |
47 changes: 47 additions & 0 deletions
47
addons/docs/src/frameworks/react/__testfixtures__/ts-function-component/properties.snapshot
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,47 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`react component properties ts-function-component 1`] = ` | ||
Object { | ||
"rows": Array [ | ||
Object { | ||
"defaultValue": Object { | ||
"detail": undefined, | ||
"summary": "true", | ||
}, | ||
"description": "Is primary?", | ||
"name": "primary", | ||
"required": false, | ||
"type": Object { | ||
"detail": undefined, | ||
"summary": "boolean", | ||
}, | ||
}, | ||
Object { | ||
"defaultValue": Object { | ||
"detail": undefined, | ||
"summary": "false", | ||
}, | ||
"description": "default is false", | ||
"name": "secondary", | ||
"required": false, | ||
"type": Object { | ||
"detail": undefined, | ||
"summary": "boolean", | ||
}, | ||
}, | ||
Object { | ||
"defaultValue": Object { | ||
"detail": undefined, | ||
"summary": "2", | ||
}, | ||
"description": "Simple click handler", | ||
"name": "onClick", | ||
"required": false, | ||
"type": Object { | ||
"detail": undefined, | ||
"summary": "signature", | ||
}, | ||
}, | ||
], | ||
} | ||
`; |
15 changes: 15 additions & 0 deletions
15
addons/docs/src/frameworks/react/react-properties.stories.tsx
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,15 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { PropsTable } from '@storybook/components'; | ||
import { extractProps } from './extractProps'; | ||
|
||
const fixtures = ['js-class-component', 'ts-function-component']; | ||
|
||
const stories = storiesOf('Properties/React', module); | ||
|
||
fixtures.forEach(fixture => { | ||
// eslint-disable-next-line import/no-dynamic-require, global-require | ||
const { component } = require(`./__testfixtures__/${fixture}/input`); | ||
const props = extractProps(component); | ||
stories.add(fixture, () => <PropsTable {...props} />); | ||
}); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also just manually do the exports so this file can be CSF