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

Injecting polyfills for vitest browser #5347

Closed
4 tasks done
edoardocavazza opened this issue Mar 6, 2024 · 7 comments · Fixed by #5656
Closed
4 tasks done

Injecting polyfills for vitest browser #5347

edoardocavazza opened this issue Mar 6, 2024 · 7 comments · Fixed by #5656
Labels
feat: browser Issues and PRs related to the browser runner p3-significant High priority enhancement (priority)

Comments

@edoardocavazza
Copy link

Clear and concise description of the problem

Vitest for browser ships with a polyfill-free policy, which is good. Sometimes we need to run tests across older browsers (such as Safari 14) that does not support features like BroadcastChannel.

Suggested solution

Add a sort of setup file for the runner to inject in index.html and tester.html files, in order to polyfill some features.

Alternative

No response

Additional context

No response

Validations

@sheremet-va
Copy link
Member

Can't you use setupFiles for this?

@edoardocavazza
Copy link
Author

Nope, they are loaded after BroadcastChannel initialization, so the polyfill won't work.

@sheremet-va
Copy link
Member

If BroadcastChannel channel is not supported by compatible versions (we use the same compatibility table that Vite Dev server uses) then we should rewrite it to use something else.

@sheremet-va sheremet-va added feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) and removed enhancement: pending triage labels Mar 26, 2024
@sheremet-va sheremet-va moved this to P2 - 3 in Team Board Mar 26, 2024
@sheremet-va sheremet-va moved this from P2 - 3 to Rejected in Team Board Mar 28, 2024
@sheremet-va
Copy link
Member

As a team, we decided that the Vitest browser mode only supports browsers that implement BroadcastChannel, this is now documented.

@edoardocavazza
Copy link
Author

It is reasonable that vitest wont support old browsers out of the box. I was just asking if you would consider to support scripts injection in order to let developers to load polyfills themselves 🙂

@sheremet-va
Copy link
Member

sheremet-va commented Apr 25, 2024

We did another round of discussion and decided it would be a good idea to expose an option to inject a script into HTML. Vitest has two HTML documents, so there will be two options.

@sheremet-va sheremet-va reopened this Apr 25, 2024
@edoardocavazza
Copy link
Author

Thank you so much!

@sheremet-va sheremet-va added p2-nice-to-have Not breaking anything but nice to have (priority) p3-significant High priority enhancement (priority) and removed p3-minor-bug An edge case that only affects very specific usage (priority) p2-nice-to-have Not breaking anything but nice to have (priority) labels Apr 25, 2024
sheremet-va added a commit to sheremet-va/vitest that referenced this issue May 2, 2024
sheremet-va added a commit to sheremet-va/vitest that referenced this issue May 3, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner p3-significant High priority enhancement (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants