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

fix(browser): remove enforce from vitest:browser plugin to simplify custom middleware plugin usage #4709

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/browser/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default (project: WorkspaceProject, base = '/'): Plugin[] => {

return [
{
enforce: 'pre',
name: 'vitest:browser',
async config(viteConfig) {
// Enables using ignore hint for coverage providers with @preserve keyword
Expand Down
4 changes: 2 additions & 2 deletions test/browser/specs/runner.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const passedTests = getPassed(browserResultJson.testResults)
const failedTests = getFailed(browserResultJson.testResults)

await test('tests are actually running', async () => {
assert.ok(browserResultJson.testResults.length === 9, 'Not all the tests have been run')
assert.ok(passedTests.length === 8, 'Some tests failed')
assert.ok(browserResultJson.testResults.length === 10, 'Not all the tests have been run')
assert.ok(passedTests.length === 9, 'Some tests failed')
assert.ok(failedTests.length === 1, 'Some tests have passed but should fail')

assert.doesNotMatch(stderr, /Unhandled Error/, 'doesn\'t have any unhandled errors')
Expand Down
7 changes: 7 additions & 0 deletions test/browser/test/cross-origin-isolated.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, it } from 'vitest'

// users can achive cross-origin isolation via custom plugin (see "coop-coep-header-middleware-plugin")
// https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated
it('crossOriginIsolated', () => {
expect(crossOriginIsolated).toBe(true)
})
12 changes: 12 additions & 0 deletions test/browser/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ export default defineConfig({
onUserConsoleLog: noop,
}, 'default'],
},
plugins: [
{
name: 'test:coop-coep-header-middleware-plugin',
configureServer(server) {
server.middlewares.use((_req, res, next) => {
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
next()
})
},
},
],
})