-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 HTTP response headers for browser tests #3743
Comments
Can't you do the same for browser tests? It uses the same config file. |
As I said, that is the config that I am using, but the headers for browser tests are not affected. |
I think the issue might be due to vitest/packages/browser/src/node/index.ts Lines 15 to 34 in 7006bb3
I think your can counter against this by setting it("repro", () => {
expect(crossOriginIsolated).toBe(true);
expect(SharedArrayBuffer).toBeDefined();
}) Side note: There seems to be a plan to run each test file in a separate iframe #3584, so if this landed, |
Maybe we can also add our middleware in the "after" hook like this? Will this fix the issue? configureServer(server) {
return () => {
server.middlewares.use(...)
}
} |
It seems "after" hook middleware doesn't work when vite config has I don't know about the consequence of forcing |
can you try using |
Adding If the tests are changed to run in separate iframes, there will need to be a way to directly customize the response headers of the frames. Hopefully that is accounted for. |
As explained in the other issue #4888, Vitest browser mode now respects Vite's import { defineConfig } from 'vite';
export default defineConfig({
server: {
headers: {
"Cross-Origin-Embedder-Policy": "require-corp",
"Cross-Origin-Opener-Policy": "same-origin"
},
},
}); |
I just tried this out with the latest versions of Vite and Vitest. It works when running the tests, but when running the app in the Vite dev server, the headers are not applied. |
Thanks for testing. Hmm... that could be a Vite side bug since This issue vitejs/vite#15641 is reported recently on Vite and it might be possible that you're seeing "304 Not modified" in devtools, but a browser should be aware of last response's header with coop/coep, so I didn't see any issue with 304 response (you may also try "disable cache" on devtools to see if it makes difference). If this also not the case, then it would be great if you can provide a reproduction and submit it as Vite issue. (Actually Vite's 304 response might be quite annoying since this probably happens also when users are tweaking |
Clear and concise description of the problem
Certain browser APIs like SharedArrayBuffer require cross-origin isolation. To enable this, the web page must be served with the below HTTP headers.
Vitest does not currently allow browser tests to set HTTP headers, so testing features that require cross-origin isolation is currently not possible.
Suggested solution
To enable this in the Vite development server, I use the following in the Vite config. Perhaps Vitest should read this same configuration to allow developers to modify the browser test's response headers.
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: