-
-
Notifications
You must be signed in to change notification settings - Fork 364
fix: wxt unit testing plugin #1844
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1844 +/- ##
==========================================
+ Coverage 80.97% 81.08% +0.11%
==========================================
Files 131 131
Lines 6679 6679
Branches 1092 1093 +1
==========================================
+ Hits 5408 5416 +8
+ Misses 1260 1252 -8
Partials 11 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@wxt-dev/analytics
@wxt-dev/auto-icons
@wxt-dev/browser
@wxt-dev/i18n
@wxt-dev/module-react
@wxt-dev/module-solid
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/runner
@wxt-dev/storage
@wxt-dev/unocss
@wxt-dev/webextension-polyfill
wxt
commit: |
@@ -183,6 +183,14 @@ | |||
"types": "./dist/testing/index.d.ts", | |||
"default": "./dist/testing/index.mjs" | |||
}, | |||
"./testing/fake-browser": { |
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.
Optionally we could remove the import above so no one can import wxt/testing
directly 🤔
"types": "./dist/testing/fake-browser.d.ts", | ||
"default": "./dist/testing/fake-browser.mjs" | ||
}, | ||
"./testing/wxt-vitest-plugin": { |
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.
I opted to follow the same testing convention of wxt/testing/wxt-vitest-plugin
we can definitely change this to wxt/wxt-vitest-plugin
if ya'll like that better 🤔
Overview
context: https://discord.com/channels/1212416027611365476/1404626135291003021/1404626135291003021
Currently there is a issue with WXT and unit testing with
jsdom
andhappy-dom
. When trying to run unit tests in each of the DOM environments you end up with the following errorsjsdom
happy-dom
Issue
The issue is that the
wxt/testing
module is importing both the vitest plugin and the fake browser. So when importing the fake browser in a unit test, its importing the vitest plugin as well which is causing these errors to happen because vitest plugin is relying in packages that don't fit the jsdom environmentFix
The fix for this to to allow importing the sub modules by themselves to prevent this conflict of interest. Now you can import just the fake browser without importing any vitest plugin code which eliminates the error
Manual Testing
Current code
produces:
Fix
│ ✓ src/entrypoints/mytest/elements/mytest.test.tsx (1 test) 27ms │ ✓ MyTest > should be able to render 25ms │ │ Test Files 1 passed (1) │ Tests 1 passed (1) │ Start at 12:33:48 │ Duration 1.43s (transform 67ms, setup 130ms, collect 117ms, tests 27ms, environment 599ms, prepare 224ms)
Related Issue
This PR closes #1575