-
-
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
Add __STORYBOOK_CLIENT_API__
for external tools
#3058
Conversation
__STORYBOOK_CLIENT_API
for external tools__STORYBOOK_CLIENT_API__
for external tools
cc @timhaines |
Codecov Report
@@ Coverage Diff @@
## master #3058 +/- ##
==========================================
- Coverage 36.87% 36.86% -0.02%
==========================================
Files 417 417
Lines 9849 9853 +4
Branches 830 839 +9
==========================================
Hits 3632 3632
+ Misses 5750 5736 -14
- Partials 467 485 +18
Continue to review full report at Codecov.
|
Yes, interested to know if this helps Percy and if there is more that would be needed at your end @timhaines |
const clientApi = new ClientApi(context); | ||
export const { storiesOf, setAddon, addDecorator, clearDecorators, getStorybook } = clientApi; | ||
// Provide access to external scripts | ||
window.__STORYBOOK_CLIENT_API__ = clientApi; |
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.
@tmeasday Is there any particular reason to do that only inside isBrowser
branch?
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.
I guess window
is not defined in the other context (i.e. jest). Are you thinking we could add it to global.__STORYBOOK_CLIENT_API__
?
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.
I would like to use it from jsdom, where window
is actually defined and is not the same as global
. My usecase is to get stories tree from node.js script
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 works in JSDOM. Have you tested it? Storybook doesn't know the difference.
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.
I literally tested this yesterday, that's why I feel quite confident about this ;)
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.
I guess I did 😊
When was that line added? That doesn't seem helpful to me.
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.
JSDOM is trying to pretend to be a browser, why would we want to treat it differently?
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.
Probably because it lacks non-dom api like postmessage that is used in channels
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.
Hmm, fair enough.
Well I think it is fine for this particular check just be something if (typeof window !== 'undefined')
but I suspect there will be other use cases for JSDOM where having isBrowser === true
might be helpful. If it breaks however I guess we leave it.
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.
Also any thoughts on #3058 (comment)
Would it perhaps also be useful to expose the channel, perhaps on |
Feel free to add as long as you're going to use it =) |
@Hypnosphi => #3243 |
So tools like Chromatic and others that interact with the client API can work with storybooks that haven't injected any code.
I would love to refactor this code from preview into core but I will leave to a later PR.
How to test
Check that
__STORYBOOK_CLIENT_API__
is defined in each example app.