storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.73k stars 9.33k forks source link

[Bug]: Configuration options don't seem to get passed on to vitest #27010

Open szpytfire opened 6 months ago

szpytfire commented 6 months ago

Describe the bug

A couple of my interaction tests are failing due to Unhandled Errors caused by an upstream dependency I'm using.

The output of the interaction test kindly suggests the following:

Unhandled Errors
Found 1 unhandled error while running the play function. This might cause false positive assertions. Resolve unhandled errors or ignore unhandled errors with setting the test.dangerouslyIgnoreUnhandledErrors parameter to true.

After reading this, I tried adding the following snippet into my .storybook/main.ts configuration:

  viteFinal: async (config, ...rest) => {
    const extraConfig = {
      test: {
        dangerouslyIgnoreUnhandledErrors: true,
      },
    };

    if (storybookConfig.viteFinal) {
      return mergeConfig(
        storybookConfig.viteFinal(config, ...rest),
        extraConfig,
      );
    }
    return mergeConfig(config, extraConfig);
  }

However, the exception is still thrown (and the interaction test still states that I need to set the test.dangerouslyIgnoreUnhandledErrors param).

Is this expected? Are parameters passed through to vitest?

To Reproduce

-

System

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M2
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 4.1.0 - ~/.nvm/versions/node/v20.11.1/bin/yarn <----- active
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 8.3.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 124.0.6367.94
    Safari: 17.2.1

Additional context

Relates to: https://github.com/xyflow/xyflow/issues/2461

jaknas commented 6 months ago

@szpytfire You need to add it to your story parameters, see: https://github.com/storybookjs/storybook/blob/a17fe0bc0cd13e702995501834674dfd9ee77aec/code/lib/preview-api/src/modules/preview-web/render/StoryRender.ts#L242-L243

szpytfire commented 6 months ago

Hey @jaknas - yep, thanks 🙏 I found this in the end after snooping around the storybook code 😄!

I wonder whether to help future users: