Skip to content
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

Merged
merged 1 commit into from
May 21, 2017
Merged

Add unit tests for addon storyshots #971

merged 1 commit into from
May 21, 2017

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Apr 28, 2017

Issue:

We didn't have a good way to test storyshots.

What I did

Added storyshots to test-cra app.

How to test

npm install
npm run bootstrap
cd examples/test-cra
npm install
npm test

@tmeasday
Copy link
Member Author

Note from commit:

Storyshots wants to plugin to the version used by the app, not have its own version. So its a clear peer dep.

Not sure it should depend on storybook at all given it is optional whether the user uses it or react-native-storybook

@ndelangen
Copy link
Member

I pushed some fixed and updated your branch, hope you don't mind 👼

"react-scripts": "0.9.5"
"react-scripts": "0.9.5",
"react-test-renderer": "^15.5.4",
"storyshots": "*"
Copy link
Member

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?

Copy link
Member

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
Copy link

codecov bot commented Apr 28, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@6f4566c). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #971   +/-   ##
=========================================
  Coverage          ?   12.51%           
=========================================
  Files             ?      196           
  Lines             ?     4458           
  Branches          ?      713           
=========================================
  Hits              ?      558           
  Misses            ?     3269           
  Partials          ?      631
Impacted Files Coverage Δ
packages/storyshots/src/index.js 0% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f4566c...b5d7247. Read the comment docs.

@ndelangen
Copy link
Member

Can this be used to help along #896 ?

@tmeasday
Copy link
Member Author

tmeasday commented May 1, 2017

Can this be used to help along #896 ?

I think #896 would be served by the alternate approach mentioned in #917

@tmeasday
Copy link
Member Author

tmeasday commented May 1, 2017

Cannot find module '@kadira/storybook-addons' from 'index.js'

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:

  1. Return @kadira/storybook-addons to be a proper dep of storyshots (this still feels wrong as it is a plugin, and making it a direct dep is asking for versioning problems).

  2. Follow this technique (https://github.com/storybooks/storybook/blob/9471a71933af45aa24c0db8d189c410809645b94/packages/storyshots/src/index.js#L15-L20) to check if the user has installed the addon package (i.e. is using any addons), and only mock if so.

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 package.json.

Any advice @ndelangen?

@ndelangen
Copy link
Member

I think not having it as a listed dependency is OK in this case as long as we guard when requiring it.

@ndelangen
Copy link
Member

@tmeasday Do you think you can finish this now? Any more feedback needed? Let me know!

@tmeasday
Copy link
Member Author

I'll get something going with that technique now.

@tmeasday
Copy link
Member Author

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)

Actually this was wrong. Storybooks depends on addons by default. The issue is that due to nested node_modules structures in this development context, storyshots can't require the correct addons.

@tmeasday
Copy link
Member Author

OK I think I finally resolved this by using the test-cra app. I suspect we should get rid of the confusing cra-storybook example @ndelangen.

@tmeasday tmeasday removed their assignment May 15, 2017
Copy link
Member

@shilman shilman left a 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.

(pkg.devDependencies && pkg.devDependencies['@kadira/react-native-storybook']) ||
(pkg.dependencies && pkg.dependencies['@kadira/react-native-storybook']);

const hasDependency = function(name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻

@tmeasday
Copy link
Member Author

Minor point: I prefer renderOnly to justRender, but it's all good.

Isn't that the other PR? I think I prefer that too..

@tmeasday
Copy link
Member Author

LMK if you want me to rebase this onto #1031

@ndelangen
Copy link
Member

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?

@tmeasday
Copy link
Member Author

@ndelangen Please!

@ndelangen
Copy link
Member

ndelangen commented May 15, 2017

pushed feel free to revert if it's 💩

@tmeasday tmeasday force-pushed the test-storyshots branch 2 times, most recently from 87c33ca to 1c8f8e0 Compare May 21, 2017 10:05
@tmeasday
Copy link
Member Author

Ok, I think I finally fixed this. The tests should pass 😬

@tmeasday
Copy link
Member Author

See commit for more detail: 1c8f8e0

Copy link
Member

@shilman shilman left a 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?


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');
Copy link
Member

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
@tmeasday tmeasday merged commit 4026bd6 into master May 21, 2017
@shilman shilman added the misc label May 27, 2017
@ndelangen ndelangen changed the title Test storyshots Add unit tests for addon storyshots May 27, 2017
@ndelangen ndelangen added the maintenance User-facing maintenance tasks label May 27, 2017
@ndelangen ndelangen deleted the test-storyshots branch July 8, 2017 22:33
Copy link

nx-cloud bot commented Mar 27, 2024

☁️ Nx Cloud Report

CI 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 target

Sent with 💌 from NxCloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants