-
-
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
Storyshots: First-class CSF support #8000
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
38d7464
First-class support of CSF in Storyshots
Hypnosphi 88863c1
Add an example with automatic displayName
Hypnosphi fa83043
Merge remote-tracking branch 'origin/next' into storyshots-csf
Hypnosphi 30537bb
Add an example with legacy storiesOf api
Hypnosphi 8dea155
Don't display parameters.fileName in Vue withData story
Hypnosphi dd199ba
Merge remote-tracking branch 'origin/next' into storyshots-csf
Hypnosphi 139f812
Merge next
Hypnosphi aa7a881
Revert test name changes
Hypnosphi 10d16d5
Add docs
Hypnosphi 091b5a8
Merge branch 'fix-local-lint' into storyshots-csf
Hypnosphi 13e1fe9
Update storyshots
Hypnosphi 4e01810
Use dedent
Hypnosphi cd20c41
Merge branch 'next' into storyshots-csf
shilman 640e591
Strip fileName from parameters story
Hypnosphi 8eeee57
Merge remote-tracking branch 'origin/next' into storyshots-csf
Hypnosphi 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
import { configure } from '@storybook/react'; | ||
|
||
const req = require.context('../stories/required_with_context', true, /\.stories\.js$/); | ||
|
||
function loadStories() { | ||
req.keys().forEach(filename => req(filename)); | ||
require('../stories/directly_required'); | ||
} | ||
|
||
configure(loadStories, module); | ||
configure( | ||
[ | ||
require.context('../stories/required_with_context', false, /\.stories\.js$/), | ||
require.context('../stories/directly_required', false, /index\.js$/), | ||
], | ||
module | ||
); |
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,11 +1,12 @@ | ||
import { configure } from '@storybook/react'; | ||
|
||
const req = require.context('../stories/required_with_context', true, /\.stories\.js$/); | ||
const req = require.context('../stories/required_with_context', false, /\.stories\.js$/); | ||
|
||
function loadStories() { | ||
req.keys().forEach(filename => req(filename)); | ||
const loadStories = () => { | ||
const result = req.keys().map(filename => req(filename)); | ||
// eslint-disable-next-line global-require | ||
require('../stories/directly_required'); | ||
} | ||
return result; | ||
}; | ||
|
||
configure(loadStories, module); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { ScriptTransformer } = require('@jest/transform'); | ||
|
||
const getNextTransformer = (fileName, config) => { | ||
const self = config.transform.find(([pattern]) => new RegExp(pattern).test(fileName)); | ||
return new ScriptTransformer({ | ||
...config, | ||
transform: config.transform.filter(entry => entry !== self), | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
process(src, fileName, config, { instrument }) { | ||
const transformer = getNextTransformer(fileName, config); | ||
const { code } = transformer.transformSource(fileName, src, instrument); | ||
|
||
return `${code}; | ||
if(exports.default != null) { | ||
exports.default.parameters = exports.default.parameters || {}; | ||
exports.default.parameters.fileName = '${fileName}'; | ||
} | ||
`; | ||
}, | ||
}; |
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
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
32 changes: 20 additions & 12 deletions
32
addons/storyshots/storyshots-core/stories/required_with_context/Button.stories.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 |
---|---|---|
@@ -1,18 +1,26 @@ | ||
import React from 'react'; | ||
|
||
import { storiesOf } from '@storybook/react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Button } from '@storybook/react/demo'; | ||
|
||
storiesOf('Button', module) | ||
.addParameters({ | ||
export default { | ||
title: 'Button', | ||
|
||
parameters: { | ||
component: Button, | ||
}) | ||
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>) | ||
.add('with some emoji', () => ( | ||
<Button onClick={action('clicked')}> | ||
<span role="img" aria-label="so cool"> | ||
😀 😎 👍 💯 | ||
</span> | ||
</Button> | ||
)); | ||
}, | ||
}; | ||
|
||
export const withText = () => <Button onClick={action('clicked')}>Hello Button</Button>; | ||
|
||
export const withSomeEmoji = () => ( | ||
<Button onClick={action('clicked')}> | ||
<span role="img" aria-label="so cool"> | ||
😀 😎 👍 💯 | ||
</span> | ||
</Button> | ||
); | ||
|
||
withSomeEmoji.story = { | ||
name: 'with some emoji', | ||
}; |
17 changes: 12 additions & 5 deletions
17
addons/storyshots/storyshots-core/stories/required_with_context/Welcome.stories.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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import React from 'react'; | ||
|
||
import { storiesOf } from '@storybook/react'; | ||
import { linkTo } from '@storybook/addon-links'; | ||
import { Welcome } from '@storybook/react/demo'; | ||
|
||
storiesOf('Welcome', module) | ||
.addParameters({ | ||
export default { | ||
title: 'Welcome', | ||
|
||
parameters: { | ||
component: Welcome, | ||
}) | ||
.add('to Storybook', () => <Welcome showApp={linkTo('Button')} />); | ||
}, | ||
}; | ||
|
||
export const toStorybook = () => <Welcome showApp={linkTo('Button')} />; | ||
|
||
toStorybook.story = { | ||
name: 'to Storybook', | ||
}; |
2 changes: 1 addition & 1 deletion
2
...storyshots-core/stories/required_with_context/__snapshots__/Async.stories.async.storyshot
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
2 changes: 1 addition & 1 deletion
2
.../storyshots/storyshots-core/stories/required_with_context/__snapshots__/Async.stories.foo
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
2 changes: 1 addition & 1 deletion
2
...shots/storyshots-core/stories/required_with_context/__snapshots__/Async.stories.storyshot
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.
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.
This documentation change differs from what is displayed in the warning below. https://github.com/storybookjs/storybook/pull/8000/files#diff-c4bcb815683c4c92762d0a868383a06cR38
Which one is the correct advice?
Yes, I know that
\\\\
is the JS equivalent of two backslashes output. However, I'm seeing all 4 backslashes on the console.Hmm… I guess I answered my own question. I should be using two backslashes in my Jest config. The bug is in the console warning showing 4 backslashes.