Skip to content

Commit 743177c

Browse files
authored
Merge branch 'main' into fix-file-url-hash-query-module-id
2 parents 0e0c033 + 92da490 commit 743177c

20 files changed

Lines changed: 119 additions & 19 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ body:
2626
id: system-info
2727
attributes:
2828
label: System Info
29-
description: Output of `npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers`
29+
description: Output of `npx envinfo --system --npmPackages '{vitest*,@vitest/*,vite,@vitejs/*,playwright,webdriverio}' --binaries --browsers`
3030
render: shell
3131
placeholder: System, Binaries, Browsers
3232
validations:

docs/api/vi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ This will clear mock history and reset each mock's implementation to its origina
409409
### vi.restoreAllMocks
410410

411411
Calls [`.mockRestore()`](/api/mock#mockrestore) on all spies.
412-
This will clear mock history, restore all original mock implementations, , and restore original descriptors of spied-on objects.
412+
This will clear mock history, restore all original mock implementations, and restore original descriptors of spied-on objects.
413413

414414
### vi.spyOn
415415

packages/browser/src/client/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const RPC_ID
1515
const METHOD = getBrowserState().method
1616
export const ENTRY_URL = `${
1717
location.protocol === 'https:' ? 'wss:' : 'ws:'
18-
}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${getBrowserState().config.name || ''}&method=${METHOD}`
18+
}//${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}`
1919

2020
let setCancel = (_: CancelReason) => {}
2121
export const onCancel = new Promise<CancelReason>((resolve) => {

packages/browser/src/client/public/esm-client-injector.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
method: { __VITEST_METHOD__ },
3131
providedContext: { __VITEST_PROVIDED_CONTEXT__ },
3232
};
33+
window.VITEST_API_TOKEN = { __VITEST_API_TOKEN__ };
3334

3435
const config = __vitest_browser_runner__.config;
3536

packages/browser/src/node/rpc.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ServerMockResolver } from '@vitest/mocker/node'
1010
import { createBirpc } from 'birpc'
1111
import { parse, stringify } from 'flatted'
1212
import { dirname } from 'pathe'
13-
import { createDebugger, isFileServingAllowed } from 'vitest/node'
13+
import { createDebugger, isFileServingAllowed, isValidApiRequest } from 'vitest/node'
1414
import { WebSocketServer } from 'ws'
1515

1616
const debug = createDebugger('vitest:browser:api')
@@ -33,6 +33,11 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
3333
return
3434
}
3535

36+
if (!isValidApiRequest(vitest.config, request)) {
37+
socket.destroy()
38+
return
39+
}
40+
3641
const type = searchParams.get('type')
3742
const rpcId = searchParams.get('rpcId')
3843
const sessionId = searchParams.get('sessionId')

packages/browser/src/node/serverOrchestrator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export async function resolveOrchestrator(
4242
__VITEST_SESSION_ID__: JSON.stringify(sessionId),
4343
__VITEST_TESTER_ID__: '"none"',
4444
__VITEST_PROVIDED_CONTEXT__: '{}',
45+
__VITEST_API_TOKEN__: JSON.stringify(globalServer.vitest.config.api.token),
4546
})
4647

4748
// disable CSP for the orchestrator as we are the ones controlling it

packages/browser/src/node/serverTester.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function resolveTester(
6868
__VITEST_SESSION_ID__: JSON.stringify(sessionId),
6969
__VITEST_TESTER_ID__: JSON.stringify(crypto.randomUUID()),
7070
__VITEST_PROVIDED_CONTEXT__: JSON.stringify(stringify(project.getProvidedContext())),
71+
__VITEST_API_TOKEN__: JSON.stringify(globalServer.vitest.config.api.token),
7172
})
7273

7374
const testerHtml = typeof browserProject.testerHtml === 'string'

packages/ui/client/components/ProgressBar.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ import { explorerTree } from '~/composables/explorer'
44
55
const { width } = useWindowSize()
66
const classes = computed(() => {
7-
// if there are no files, then in progress and gray
8-
if (explorerTree.summary.files === 0) {
9-
return '!bg-gray-4 !dark:bg-gray-7 in-progress'
10-
}
11-
else if (!finished.value) {
12-
return 'in-progress'
13-
}
14-
15-
return null
7+
return [
8+
explorerTree.summary.files === 0 && '!bg-gray-4 !dark:bg-gray-7',
9+
!finished.value && 'in-progress',
10+
].filter(Boolean).join(' ')
1611
})
1712
1813
const widthPass = computed(() => {
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
<script setup lang="ts">
2+
import { finished } from '~/composables/client/state'
3+
import { explorerTree } from '~/composables/explorer'
4+
</script>
5+
16
<template>
27
<div gap-0 flex="~ col gap-4" h-full justify-center items-center>
3-
<!-- <div bg-header rounded-lg p="y4 x2"> -->
8+
<template v-if="explorerTree.summary.files === 0 && finished">
9+
<div class="text-gray-5">
10+
No tests found
11+
</div>
12+
</template>
413
<section aria-labelledby="tests" m="y-4 x-2">
514
<TestsEntry />
615
</section>
716
<TestFilesEntry />
8-
<!-- </div> -->
917
</div>
1018
</template>

packages/ui/client/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export const PORT = import.meta.hot && !browserState ? '51204' : location.port
44
export const HOST = [location.hostname, PORT].filter(Boolean).join(':')
55
export const ENTRY_URL = `${
66
location.protocol === 'https:' ? 'wss:' : 'ws:'
7-
}//${HOST}/__vitest_api__`
7+
}//${HOST}/__vitest_api__?token=${(window as any).VITEST_API_TOKEN}`
88
export const isReport = !!window.METADATA_PATH
99
export const BASE_PATH = isReport ? import.meta.env.BASE_URL : __BASE_PATH__

0 commit comments

Comments
 (0)