You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"browser" export condition is not set when testing with jsdom #7215
Now, development is set, so unless browser is also set, it will always be false. I know you can set export conditions in Vite, but I haven't seen anything similar in Vitest. I'd expect it to be set when using a browser environment, probably using an option or similar.
I found this way to mock it, it works for me but I believe the property is also used by SvelteKit's vite plugin, which won't see this change, so there's some edge cases in which it might not work:
Interestingly you cannot wrap the entire call in an if (typeof window == "object") as the mock somehow leaks into tests for which the check fails, this way it re-mocks it and removes the property for those.
Hello @rChaoz. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.
However, not doing this for jsdom/happy-dom is probably intentional since they are only emulation on Node and forcing browser condition for all packages can cause more issues on Vitest. For example, even loading jsdom seems to be causing an issue with browser condition.
Let me close this as resolve.conditions with browser technically works with a caveat that some packages can get broken as they don't expect to be used on Node.
If you need to mock esm-env mocking on svelte-kit testing, then that sounds like its own big topic, so please follow up in a separate issue.
Activity
github-actions commentedon Jan 12, 2025
Hello @rChaoz. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with
needs reproductionwill be closed if they have no activity within 3 days.rChaoz commentedon Jan 12, 2025
@hi-ogawa hi, just added a stackblitz repro
hi-ogawa commentedon Jan 12, 2025
Technically you can add conditions in the same way as Vite via
resolve.conditionshttps://stackblitz.com/edit/vitest-dev-vitest-hpqypsft?file=vite.config.tsHowever, not doing this for jsdom/happy-dom is probably intentional since they are only emulation on Node and forcing
browsercondition for all packages can cause more issues on Vitest. For example, even loadingjsdomseems to be causing an issue withbrowsercondition.rChaoz commentedon Jan 12, 2025
I did not know that, but I guess it makes sense, so mocking
esm-envmight be the best solution.hi-ogawa commentedon Jan 13, 2025
Let me close this as
resolve.conditionswithbrowsertechnically works with a caveat that some packages can get broken as they don't expect to be used on Node.If you need to mock
esm-envmocking on svelte-kit testing, then that sounds like its own big topic, so please follow up in a separate issue.