-
Notifications
You must be signed in to change notification settings - Fork 12
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
Setup testing framework vitest #28
Conversation
🦋 Changeset detectedLatest commit: 52e7ca4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Change: +26 B (0%) Total Size: 3.61 MB
ℹ️ View Unchanged
|
000114b
to
958097f
Compare
958097f
to
b07899f
Compare
// HACK: Fixes vitest browser runner | ||
globalThis.__vitest_browser_runner__ = { wrapDynamicImport: (foo) => foo() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not pretty... TODO: open up an issue upstream to report the bug
Setup vitest for testing library code.
Configuring this properly was tricky. Since the library heavily relies on browser APIs like web workers & wasm, it doesn't really make sense to mock the browser APIs for unit tests. To trust our tests in this library, we really need them to run in a realistic browser environment.
Vitest browser mode + playwright (provider) seems to satisfy all our needs. It spins up a real browser to run tests and can run headlessly for CI. I had to add one hack to make it work with the web-worker, but otherwise it seems to work well out of the box.
This framework should be suitable for all the additional libraries we have planned (e.g. react).