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

Script always fails with error "Storybook object not found on window. Open your storybook and check the console for errors." #44

Closed
karrui opened this issue Oct 28, 2021 · 13 comments · Fixed by #45

Comments

@karrui
Copy link

karrui commented Oct 28, 2021

When running my CLI command (regardless of config), the cli always hangs with the following output:

$ npm run test:a11y -- --headless false --browser firefox

> form-frontend@0.1.0 test:a11y /Users/karrui/Projects/FormSG/frontend
> axe-storybook "--headless" "false" "--browser" "firefox"

[firefox] accessibility
Error! The suite failed to run
An error was encountered before we started testing stories. Likely this means the browser failed to open.

Error: Storybook object not found on window. Open your storybook and check the console for errors.

0 passing (0ms)
1 failing
0 pending
@ahuth
Copy link
Collaborator

ahuth commented Oct 28, 2021

@karrui which version of Storybook are you using?

This doesn't yet support Storybook v6.4 (although I'm working on that).

@karrui
Copy link
Author

karrui commented Oct 28, 2021

which version of Storybook are you using?

Ah, I should have included that information. I'm using 6.3.12 right now. Seems like percy-storybook, a project this project seems to be based on has had a similar issue (percy/percy-storybook#230) if that helps

@karrui karrui changed the title Script always fails Script always fails with error "Storybook object not found on window. Open your storybook and check the console for errors." Oct 28, 2021
@karrui
Copy link
Author

karrui commented Oct 28, 2021

On further investigation, it may be due to the msw storybook addon, and it is intercepting the puppeteer requests, if that helps better debug this.

See mswjs/msw-storybook-addon#55

@ahuth
Copy link
Collaborator

ahuth commented Oct 28, 2021

Ah, gotcha, thanks for the info. That's super helpful. I'll look into what's going on there, and how we could prevent the msw addon from intercepting the requests.

What's interesting is my company uses MSW heavily but doesn't have any issues, although we don't use that addon.

@ahuth ahuth closed this as completed Oct 28, 2021
@ahuth ahuth reopened this Oct 28, 2021
@karrui
Copy link
Author

karrui commented Oct 28, 2021

Might have been a red herring; I've removed the decorator and it's still giving me the same error.

But it might have something to do with it; I was going down a different path with @storybook/addon-storyshots and it also did not work at the start. However, it works when I removed the msw decorator.

@ahuth
Copy link
Collaborator

ahuth commented Oct 28, 2021

One thing to help debug, @karrui:

Can you open the iframe.html that's produced as part of your static storybook build? When you do, do you see something like

Screen Shot 2021-10-28 at 9 20 58 AM

Just want to see if Storybook itself is even loading (seems like it's not, but want to make sure).

@karrui
Copy link
Author

karrui commented Oct 28, 2021

Thanks for being so active in this issue!

That was one of the first things I checked; I do see that iframe.

@ahuth
Copy link
Collaborator

ahuth commented Oct 28, 2021

No prob.

I'll look into this some more, and try to reproduce with msw addon.

@ahuth
Copy link
Collaborator

ahuth commented Oct 28, 2021

@karrui I added msw and its addon to the demo in this repo, and wasn't able to reproduce.

Can you give me any info about what routes are being mocked by msw? Or is there any chance your work is in a repo/branch I can pull down and look at?

@karrui
Copy link
Author

karrui commented Oct 29, 2021

Actually, yes. The repo I'm working on is open source; you can find it here.

Ensure that you are on the form-v2/build/a11y-ci branch and pull away! I'm specifically only using it in the /frontend directory.

ahuth added a commit that referenced this issue Oct 29, 2021
…ywright

This is necessary because Playwright's `page.evaluate` requires return values to be JSON
serializable, so we need to make sure there are no non-serializable things in this object.
There's no telling what Storybook addons people are using, and whether their parameters are
serializable or not.

See #44 for a bug caused by this.
@ahuth
Copy link
Collaborator

ahuth commented Oct 29, 2021

Alright, fix coming in #45. Will let you know when it's published, and thanks for reporting the issue!

What's happening is:

  • The axe-storybook is a node command that uses Playwright to get some information about the stories from a browser pointed at the static Storybook build.
  • Getting that information out of the browser requires it to be JSON serializable.
  • Some addon parameters (such as MSW's) aren't JSON serializable, causing undefined to be returned.

We can avoid that by only retrieving the information we know we need, instead of trying to get everything out of the browser.

@ahuth ahuth closed this as completed in #45 Oct 29, 2021
@ahuth
Copy link
Collaborator

ahuth commented Oct 29, 2021

4.1.3 is released with the fix. @karrui when you get a chance, can you verify that it solves the issue for you? (It does in my testing on the repo)

@karrui
Copy link
Author

karrui commented Oct 30, 2021

Awesome, it works now. Once again, thanks for such a quick response!

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

Successfully merging a pull request may close this issue.

2 participants