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

[Bug] HTML Injection ignored by vitest plugin #29776

Closed
Tracked by #29770 ...
vanessayuenn opened this issue Dec 2, 2024 · 0 comments · Fixed by #29808
Closed
Tracked by #29770 ...

[Bug] HTML Injection ignored by vitest plugin #29776

vanessayuenn opened this issue Dec 2, 2024 · 0 comments · Fixed by #29808

Comments

@vanessayuenn
Copy link
Contributor

Related to #29775

Users can define custom HTML files to inject scripts/style in Storybook's preview by adding a .storybook/preview-head.html or .storybook/preview-body.html file. This is automatically loaded in Storybook, but ignored in the Vitest plugin.

💡 Solutions/Action items:

  • We can leverage the browser.testerHtmlPath to inject an HTML file into the test run, so that property could be automatically added internally via the Vitest plugin:

    // vitest.workspace.js
    export default defineWorkspace([{
        test: {
          browser: {
            testerHtmlPath: '.storybook/preview-head.html',
            // ...
          },
        }
    }])

This solution however only allows for a single file to be added. We could instead read the contents of these preview html files and leverage the [transformIndexHtml](https://vite.dev/guide/api-plugin#transformindexhtml) plugin hook as mentioned in the previous section to inject them into the test run.

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

Successfully merging a pull request may close this issue.

2 participants