-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Allow promise to be returned from 'add()' #1670
Conversation
+1 this feature would be useful |
Codecov Report
@@ Coverage Diff @@
## release/3.3 #1670 +/- ##
===============================================
- Coverage 23.34% 21.65% -1.69%
===============================================
Files 277 252 -25
Lines 6041 5717 -324
Branches 709 704 -5
===============================================
- Hits 1410 1238 -172
+ Misses 4133 3957 -176
- Partials 498 522 +24
Continue to review full report at Codecov.
|
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.
Code looks good
not tested yet
Please resolve linting errors
Hey @dchambers code looks good to me, and with a clear use-case described here I think we can get this rolling. I think a unit-test or 2 to test this, a note of this in the docs somewhere would be nice. |
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 need an example usage that is snapshotted in a kitchen sink
Hi @ndelangen, I've taken quite a good look at the tests that currently exist and can't find anything that looks like it would be able to verify this new functionality. I guess part of the problem is that what's there at present seems to be more like unit tests rather than BDD tests that test the actual behaviour, and in this case unit testing that some promises were added wouldn't seem to really prove anything. If I were to add someting then the Regarding docs, I have now added a description of the feature that will hopefully be helpful to people. Thanks again! |
@@ -1,7 +1,8 @@ | |||
--- | |||
* * * |
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.
Can you revert these lines?, sorry, it's not your fault, the markdown linter needs a patch, But I haven't found the time to understand what changed/broke.
I think the fastest way to get coverage and confidence is to add a story to a kitchen sink that actually uses this feature! |
@dchambers Are you interested in finishing this PR by processing the review comments I left for you? Anything you need from me? Anything unclear? Please let me know, I can take over if you'd like. |
Hi @ndelangen, yes apologies, I've been crazy busy with work the last two weeks, including this weekend. I'm fairly confident I'll be able to make some time to work through the issues you've identified on Monday, if not Sunday. Thanks, Dominic 👍 |
Apologies again for not progressing this at the start of this week as promised. I've still been crazy busy with work. I've now definitely got time to dedicate to this on Friday and Saturday though, so will get everything resolved then. Thanks for your patience on this one 👍 |
Rebased for you 👍 , can you check everything is as it should be? |
Also fixed a subtle bug in the code that only showed up on running `npm run build-packs`.
Thanks @ndelangen. It's not quite working yet, but I've just pushed an attempt at a kitchen-sink that is hopefully in the right direction. |
Why a separate kitchen-sink? |
Good point @Hypnosphi, some storybook tests where one of the stories uses a promise could just as easily be added to the existing One question though, unlike some of the other kitchen-sinks, the CRA one appears to be testing versioned releases of storybook (e.g. |
This magic is called lerna: https://lernajs.io We prefer to keep all examples in one kitchen-sink React Native examples are a bit special, because they use RN-specific packager. That’s why they are excluded from lerna setup: |
This is broken in combination with decorators... Looking for a possible solution. |
Found a solution, I think |
…cra-kitchen-sink IMPROVE the in-code comments
A story really should be a function, otherwise all request would happen immediately upon visiting storybook, this should only happen when visiting that particular story.
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.
So the decorator stuff needs to be reviewed and tested really carefully!!!
There's a few alternatives:
- Render stories twice to detect if it's an async story
- have an api specific for async stories
- do not support decorators for async stories (harder than you think)
What's the risk here?
Well this changes the order of execution of storyFn and decorators.
the storyFn gets the context object earlier then before this change, the decorators get the context object after. I'm unsure what the impact of this really is.
Context has always been -blegh- to me.
What this would like break/change in behavior is if someone was doing this: (which I haven't seen anyone do)
storiesOf('Aliens')
.add(context => <Alien name={'jimmy'} stuff={context} />)
Please advice @Hypnosphi @storybooks/team
Obviously unit-tests needs fixing / storyshots needs a fix. I hope we can have some more eyes looking for on the potential impact on this! |
Is this something we should be considering alongside the mooted changes to the addon API? |
What was the initial point of passing
Maybe it's supposed that the decorator can somehow affect that function's output before calling it? |
Maybe in
Then async stories could be supported with promise decorator:
|
Closing this because there hasn't been any activity here for a while. Feel free to reopen when this is ready for discussion again. |
Having trouble following this -- is there still no support for any form of async story definition/rendering? This feature is vital ... |
I got confirmation that this feature was never finished. What is the appetite to get this effort started again? Or is there a plan for this to be inherent in the v4 release? |
I have been trying this in 5.2 and it seems this is still not supported. Seems there is an alternative constructs available for using async data in stories. Maybe someone could suggest some directions? This is what I tried and it doesn't work as add doesn't support promises
|
@husayt in
You may want to extract a custom hook to reuse this kind of logic:
|
@Hypnosphi Thank you for the direction. I have been playing with this since then, but seems it is not ready yet. This is what I ended up with:
Let me go through issues I faced.
But still after all this data doesn't get updated on the Vue component. Vue is not getting updates to I see So seems like these are Vue related issues. Most probably we are jumping ahead of the line with that, as nowhere it is mentioned that this is expected to work with Vue. BUt I can see how extremely powerful this can be |
I'll update my previous comment with your edits. As for issues with updates, I'm no expert in Vue, but maybe you should use |
FWIW, this is a partial fix for #713.
There are no docs, I haven't promisified the other test functions in storyshot (only
snapshotWithOptions
), and there are no unit tests.