Skip to content

Commit 5b16483

Browse files
authored
fix(browser): encode projectName in browser client URL (#9523)
1 parent d73b291 commit 5b16483

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

packages/browser/src/client/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const RPC_ID: string
1818
const METHOD = getBrowserState().method
1919
export const ENTRY_URL: string = `${
2020
location.protocol === 'https:' ? 'wss:' : 'ws:'
21-
}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${getBrowserState().config.name || ''}&method=${METHOD}&token=${(window as any).VITEST_API_TOKEN || '0'}`
21+
}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${encodeURIComponent(getBrowserState().config.name || '')}&method=${METHOD}&token=${(window as any).VITEST_API_TOKEN || '0'}`
2222

2323
const onCancelCallbacks: ((reason: CancelReason) => void)[] = []
2424

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, test } from 'vitest'
2+
3+
test('basic test', () => {
4+
expect(true).toBe(true)
5+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
name: 'Components & Hooks',
6+
browser: {
7+
enabled: true,
8+
headless: true,
9+
},
10+
},
11+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, test } from 'vitest'
2+
import { instances, provider, runBrowserTests } from './utils'
3+
4+
test('runs tests correctly when project name contains special characters', async () => {
5+
const { stderr, stdout, exitCode, ctx } = await runBrowserTests({
6+
root: './fixtures/project-name-encoding',
7+
browser: {
8+
provider,
9+
instances,
10+
},
11+
})
12+
13+
expect(stderr).toBe('')
14+
expect(exitCode).toBe(0)
15+
16+
const projectName = ctx.config.name
17+
18+
instances.forEach(({ browser }) => {
19+
expect(stdout).toReportPassedTest('basic.test.ts', `${projectName} (${browser})`)
20+
})
21+
})

0 commit comments

Comments
 (0)