-
-
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
Add unit tests for addon storyshots #971
Conversation
Note from commit:
|
I pushed some fixed and updated your branch, hope you don't mind 👼 |
examples/cra-storybook/package.json
Outdated
"react-scripts": "0.9.5" | ||
"react-scripts": "0.9.5", | ||
"react-test-renderer": "^15.5.4", | ||
"storyshots": "*" |
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 should this also be a file://...
dependency like the other ones @ndelangen added? or does lernajs automagically do the right thing here?
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.
Lerna will do it's thing on that!
Codecov Report
@@ Coverage Diff @@
## master #971 +/- ##
=========================================
Coverage ? 12.51%
=========================================
Files ? 196
Lines ? 4458
Branches ? 713
=========================================
Hits ? 558
Misses ? 3269
Partials ? 631
Continue to review full report at Codecov.
|
Can this be used to help along #896 ? |
Hmmm. This test is failing because I changed the dependency in storyshots to a peer dep, and the example project isn't using an addon (so as a result addons never gets installed). I can see two solutions to the problem:
I'm not sure of the best way to do 2. If you make the package a peer dep, and the user isn't using it, they will get a warning from npm, but things will work fine. This seems suboptimal though. The alternative is to just not specify anything in Any advice @ndelangen? |
I think not having it as a listed dependency is OK in this case as long as we guard when requiring it. |
@tmeasday Do you think you can finish this now? Any more feedback needed? Let me know! |
I'll get something going with that technique now. |
Actually this was wrong. Storybooks depends on addons by default. The issue is that due to nested |
OK I think I finally resolved this by using the |
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.
Looks great!
Minor point: I prefer renderOnly
to justRender
, but it's all good.
OOPS WRONG PR.
packages/storyshots/src/index.js
Outdated
(pkg.devDependencies && pkg.devDependencies['@kadira/react-native-storybook']) || | ||
(pkg.dependencies && pkg.dependencies['@kadira/react-native-storybook']); | ||
|
||
const hasDependency = function(name) { |
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.
😻
Isn't that the other PR? I think I prefer that too.. |
LMK if you want me to rebase this onto #1031 |
I was actually working on this / checking it out last evening and got pretty far, but not quite so far tests were passing. I'll work on it some more. I can also push my changes, and have you take a look at it? |
@ndelangen Please! |
pushed feel free to revert if it's 💩 |
87c33ca
to
1c8f8e0
Compare
Ok, I think I finally fixed this. The tests should pass 😬 |
See commit for more detail: 1c8f8e0 |
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.
Does the options.mode
flag need to be added to docs?
addons/storyshots/src/index.js
Outdated
|
||
export default function testStorySnapshots(options = {}) { | ||
addons.setChannel(createChannel()); | ||
|
||
const isStorybook = options.mode === 'react' || hasDependency('@storybook/react'); | ||
const isRNStorybook = options.mode === 'react' || hasDependency('@storybook/react-native'); |
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.
should be react-native
?
A few things involved: 1. Remove dependencies from storyshots Storyshots wants to plugin to the version used by the app, not have its own version. So it should probably use a peer dep; however as some deps are optional (i.e. react vs react-native) this will lead to confusing warnings to the user. This seems like an OK approach until we hear differently from users. 2. Update test-cra's react-scripts to get it's Jest version up to date 3. Add a `mode` option to storyshots to avoid it auto-detecting if `@storybooks/react[-native]` is installed (this was breaking Jest run from the top-level). 4. Ensure that travis installs the `test-cra` properly
☁️ Nx Cloud ReportCI is running/has finished running commands for commit b5d7247. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Issue:
We didn't have a good way to test storyshots.
What I did
Added storyshots to
test-cra
app.How to test