tuchk4 / storybook-readme

React Storybook addon to render README files in github style

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Addon breaks storyshots/jest due to assuming browser env

w33ble opened this issue · comments

When using this addon along with @storybook/addon-storyshots, I get the following error when trying to run the tests:

Test suite failed to run

    ReferenceError: window is not defined

      at Object.<anonymous> (node_modules/storybook-readme/backwardCompatibility/index.js:26:1)
      at Object.<anonymous> (node_modules/storybook-readme/backwardCompatibility/with-docs.js:13:9)

Since this addon isn't running in a browser when using Jest, window is undefined.

Fixing that, I get:

ReferenceError: document is not defined

      at insert (node_modules/storybook-readme/styles/styleFactory.js:42:7)
      at ReadmeContent.componentDidMount (node_modules/storybook-readme/components/ReadmeContent/index.js:108:40)

PR looks ok but I have not issues with storyshoots even before PR merges

How did you run it?

FYI: related PR merged and released in 5.0.6

I figured out the issue I was having, sorry for not following up here. I was running Jest in node mode, instead of jsdom mode, so none of the DOM stuff worked. I've since switch that.

Re-closing since the fix is in anyway, and you're welcome to revert #193 if you're so inclined. Adding something to the docs about that might be helpful for folks in the future who, like me, configure Jest wrong 😛.

FYI, this is the config setting: https://jestjs.io/docs/en/configuration.html#testenvironment-string (jsdom is the default, but for some reason I had it set to node).