Skip to content

Commit 1d8ebf9

Browse files
authored
feat(browser): use base url instead of __vitest__ (#8126)
1 parent dfe81a6 commit 1d8ebf9

File tree

7 files changed

+10
-9
lines changed

7 files changed

+10
-9
lines changed

packages/browser/src/client/orchestrator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { relative } from 'pathe'
66
import { getUiAPI } from './ui'
77
import { getBrowserState, getConfig } from './utils'
88

9-
const url = new URL(location.href)
109
const ID_ALL = '__vitest_all__'
1110

1211
export class IframeOrchestrator {
@@ -187,7 +186,7 @@ export class IframeOrchestrator {
187186

188187
private createTestIframe(iframeId: string) {
189188
const iframe = document.createElement('iframe')
190-
const src = `${url.pathname}__vitest_test__/__test__/?sessionId=${getBrowserState().sessionId}&iframeId=${iframeId}`
189+
const src = `/?sessionId=${getBrowserState().sessionId}&iframeId=${iframeId}`
191190
iframe.setAttribute('loading', 'eager')
192191
iframe.setAttribute('src', src)
193192
iframe.setAttribute('data-vitest', 'true')

packages/browser/src/node/middlewares/orchestratorMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function createOrchestratorMiddleware(parentServer: ParentBrowserProject)
99
return next()
1010
}
1111
const url = new URL(req.url, 'http://localhost')
12-
if (url.pathname !== parentServer.base) {
12+
if (url.pathname !== parentServer.prefixOrchestratorUrl) {
1313
return next()
1414
}
1515

packages/browser/src/node/middlewares/testerMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function createTesterMiddleware(browserServer: ParentBrowserProject): Con
99
return next()
1010
}
1111
const url = new URL(req.url, 'http://localhost')
12-
if (!url.pathname.startsWith(browserServer.prefixTesterUrl) || !url.searchParams.has('sessionId')) {
12+
if (url.pathname !== browserServer.prefixTesterUrl || !url.searchParams.has('sessionId')) {
1313
return next()
1414
}
1515

packages/browser/src/node/pool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ class BrowserPool {
248248
this.project,
249249
this,
250250
)
251-
const url = new URL('/', this.options.origin)
251+
const browser = this.project.browser!
252+
const url = new URL('/__vitest_test__/', this.options.origin)
252253
url.searchParams.set('sessionId', sessionId)
253-
const pagePromise = this.project.browser!.provider.openPage(
254+
const pagePromise = browser.provider.openPage(
254255
sessionId,
255256
url.toString(),
256257
)

packages/browser/src/node/projectParent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class ParentBrowserProject {
2626
public testerScripts: HtmlTagDescriptor[] | undefined
2727

2828
public faviconUrl: string
29+
public prefixOrchestratorUrl: string
2930
public prefixTesterUrl: string
3031
public manifest: Promise<Vite.Manifest> | Vite.Manifest
3132

@@ -108,7 +109,8 @@ export class ParentBrowserProject {
108109
this.commands[command] = project.config.browser.commands[command]
109110
}
110111

111-
this.prefixTesterUrl = `${base}__vitest_test__/__test__/`
112+
this.prefixTesterUrl = `${base || '/'}`
113+
this.prefixOrchestratorUrl = `${base}__vitest_test__/`
112114
this.faviconUrl = `${base}__vitest__/favicon.svg`
113115

114116
this.manifest = (async () => {

packages/vitest/src/node/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class Logger {
252252
const providerString = provider === 'preview' ? '' : ` by ${c.reset(c.bold(provider))}`
253253
this.log(
254254
c.dim(
255-
`${output}Browser runner started${providerString} ${c.dim('at')} ${c.blue(new URL('/', origin))}\n`,
255+
`${output}Browser runner started${providerString} ${c.dim('at')} ${c.blue(new URL('/__vitest_test__/', origin))}\n`,
256256
),
257257
)
258258
}

test/browser/fixtures/mocking-out-of-root/project1/vitest.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default defineConfig({
1414
screenshotFailures: false,
1515
headless: true,
1616
instances,
17-
headless: true,
1817
},
1918
},
2019
})

0 commit comments

Comments
 (0)