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

Added safety net preventing storybook Jest addon from throwing. #3023

Merged
merged 4 commits into from
Feb 19, 2018
Merged

Added safety net preventing storybook Jest addon from throwing. #3023

merged 4 commits into from
Feb 19, 2018

Conversation

tniezg
Copy link
Contributor

@tniezg tniezg commented Feb 19, 2018

Added safety net preventing storybook Jest addon from throwing on unrecognized test results and forcing those results to be returned no matter their format.

Issue:
Storybook's Jest addon throws an Error when one of failed tests is a Jest snapshot and is not fully recognized by it.

What I did

Used enzyme-to-json to make better snapshots of React components in Jest when using Enzyme to render them. Failed tests would throw an exception in Storybook's Jest addon, because the addon could not fully recognize the format of the output.

How to test

  1. Use a custom Jest serializer for snapshots, for example enzyme-to-json, and output a failed test by running Jest.
  2. Load Jest's output in Storybook's Jest addon.
  3. You will see an Error in the web console stating that reduce cannot receive an object. This is due to one of reducers inside Storybook's Jest addon being unable to properly parse Jest's output and returning an object instead of an array for the next reducer.

Is this testable with jest or storyshots?
Jest

Does this need a new example in the kitchen sink apps?
No

Does this need an update to the documentation?
No

If your answer is yes to any of these, please make sure to include it in your PR.

…ecognized test results and forcing those results to be returned no matter their format.
@tniezg
Copy link
Contributor Author

tniezg commented Feb 19, 2018

This is not supposed to be a perfect solution to the issue but a fallback for when everything else fails. Ideally, the addon would recognize failed snapshot tests and format them correctly. For now, though, I think it's better to have a solution such as the one provided, that allows Storybook to continue working than have it fail completely.

@codecov
Copy link

codecov bot commented Feb 19, 2018

Codecov Report

Merging #3023 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3023   +/-   ##
=======================================
  Coverage   37.28%   37.28%           
=======================================
  Files         435      435           
  Lines        9432     9432           
  Branches      909      926   +17     
=======================================
  Hits         3517     3517           
+ Misses       5375     5336   -39     
- Partials      540      579   +39
Impacted Files Coverage Δ
addons/jest/src/components/Result.js 0% <0%> (ø) ⬆️
app/polymer/src/server/config/babel.js 0% <0%> (-100%) ⬇️
app/polymer/src/server/babel_config.js 0% <0%> (-76.67%) ⬇️
lib/ui/src/modules/ui/routes.js 0% <0%> (ø) ⬆️
lib/components/src/table/table.js 83.33% <0%> (ø) ⬆️
lib/ui/src/modules/ui/components/search_box.js 36.36% <0%> (ø) ⬆️
lib/ui/src/modules/ui/libs/filters.js 48.64% <0%> (ø) ⬆️
lib/core/src/server/config/env.js 0% <0%> (ø) ⬆️
addons/info/src/components/types/Enum.js 0% <0%> (ø) ⬆️
addons/jest/src/components/Indicator.js 0% <0%> (ø) ⬆️
... and 63 more

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 c8d4fbf...6e33fd2. Read the comment docs.

@Hypnosphi Hypnosphi added addon: jest patch:yes Bugfix & documentation PR that need to be picked to main branch bug labels Feb 19, 2018
@Hypnosphi Hypnosphi merged commit 4f545e8 into storybookjs:master Feb 19, 2018
shilman pushed a commit that referenced this pull request Feb 21, 2018
Added safety net preventing storybook Jest addon from throwing.
@Hypnosphi Hypnosphi added patch:done Patch/release PRs already cherry-picked to main/release branch and removed patch:done Patch/release PRs already cherry-picked to main/release branch labels Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: jest bug patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants