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

Setup testing framework vitest #28

Merged
merged 7 commits into from
Sep 20, 2024
Merged

Setup testing framework vitest #28

merged 7 commits into from
Sep 20, 2024

Conversation

alexlwn123
Copy link
Collaborator

@alexlwn123 alexlwn123 commented Sep 20, 2024

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).

Copy link

changeset-bot bot commented Sep 20, 2024

🦋 Changeset detected

Latest commit: 52e7ca4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@fedimint/core-web Patch

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

Copy link
Contributor

github-actions bot commented Sep 20, 2024

Size Change: +26 B (0%)

Total Size: 3.61 MB

Filename Size Change
packages/core-web/dist/index.js 1.75 kB -25 B (-1.41%)
packages/core-web/dist/worker.js 584 B +51 B (+9.57%) ⚠️
ℹ️ View Unchanged
Filename Size
packages/core-web/wasm/fedimint_client_wasm_bg.wasm 3.61 MB

compressed-size-action

@alexlwn123 alexlwn123 force-pushed the alex/setup-vitest branch 3 times, most recently from 000114b to 958097f Compare September 20, 2024 19:20
Comment on lines +3 to +4
// HACK: Fixes vitest browser runner
globalThis.__vitest_browser_runner__ = { wrapDynamicImport: (foo) => foo() }
Copy link
Collaborator Author

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

@alexlwn123 alexlwn123 merged commit 779e924 into main Sep 20, 2024
5 checks passed
@alexlwn123 alexlwn123 deleted the alex/setup-vitest branch September 20, 2024 19:34
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 this pull request may close these issues.

1 participant