- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 227
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
Allow setting the base URL #868
Comments
@capricorn86 I was able to set the base URL via https://vitest.dev/config/#environment, I only know about vitest as my runner but looks like vitest could maybe have the environmentOptions, I assume whatever runner would have similar abilities. |
This does seem to work for me, thank you @kalvenschraut! |
I encountered the same problem when trying to setup happy-dom with MSW. I'd vote for using http://localhost as default, to be consistent with js-dom. |
@X-Y I believe that JSDom also defaults to "about:blank", but the test framework probably sets it to "http://localhost" in that case. Defaulting to "http://localhost" can potentially cause security issues as it will affect functionality such as CORS and cookies. JSDom source code: |
The reason why MSW throws is because it's using If the default |
@silvenon The simplest solution would probably be if Vitest sets the URL to "https://localhost" or similar. In Vitest we at least know that we are simulating a local environment. It doesn't feel right to me if Happy DOM sets a default URL. |
This has now been fixed in v0.34.2 version of Vitest. Vitest pull request: |
Sorry, I closed this a bit too quick. The issue is about Jest and not Vitest. I believe that I misunderstood what the original issue was about. I will make a fix now that sets the base URL for the Jest environment. |
…base-url #868@patch: Sets default URL for @happy-dom/jest-environment to "http…
@akaltar sorry for misunderstanding the original issue. There is now a fix for You can read more about the release here: |
Is your feature request related to a problem? Please describe.
When trying to migrate from
jest-environment-jsdom
I'm experiencing lots of issues aroundabout:blank
being the base URL because I'm trying to construct relative URLsDescribe the solution you'd like
Allow configuring the base URL in the base package + maybe change default for jest environment to match jsdom
Describe alternatives you've considered
I'm just trying happy-dom out, but I'm not sure how could I override this without a feature in my test setup. Adding the base URL everywhere in this big project feels a bit too difficult
Additional context
Very closely related to discussion in #678
The text was updated successfully, but these errors were encountered: