Skip to content

Commit 8f6f9a6

Browse files
authored
Merge branch 'main' into main
2 parents 69299a2 + b526896 commit 8f6f9a6

File tree

21 files changed

+99
-50
lines changed

21 files changed

+99
-50
lines changed

docs/config/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,8 @@ export default defineConfig({
13511351
```
13521352

13531353
::: tip NOTE
1354-
Vitest automatically adds test files `include` patterns to the default value of `coverage.exclude`.
1354+
Vitest automatically adds test files `include` patterns to the `coverage.exclude`.
1355+
It's not possible to show coverage of test files.
13551356
:::
13561357

13571358
#### coverage.all

docs/guide/migration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ This function is not used internally and exposed exclusively as a public API.
8585

8686
The `vitest/reporters` entrypoint now only exports reporters implementations and options types. If you need access to `TestCase`/`TestSuite` and other task related types, import them additionally from `vitest/node`.
8787

88+
### Coverage ignores test files even when `coverage.excludes` is overwritten.
89+
90+
It is no longer possible to include test files in coverage report by overwriting `coverage.excludes`. Test files are now always excluded.
91+
8892
## Migrating to Vitest 2.0 {#vitest-2}
8993

9094
### Default Pool is `forks`

examples/lit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"coverage": "vitest run --coverage",
1111
"dev": "vite",
1212
"test": "vitest",
13+
"list": "vitest list",
1314
"test:ui": "vitest --ui"
1415
},
1516
"dependencies": {

examples/lit/vite.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export default defineConfig({
99
// https://lit.dev/docs/tools/testing/#testing-in-the-browser
1010
browser: {
1111
enabled: true,
12-
name: 'chromium',
1312
provider: 'playwright',
13+
instances: [
14+
{ browser: 'chromium' },
15+
],
1416
},
1517
},
1618
})

packages/browser/src/client/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ export const RPC_ID
1212
= PAGE_TYPE === 'orchestrator'
1313
? getBrowserState().sessionId
1414
: getBrowserState().testerId
15+
const METHOD = getBrowserState().method
1516
export const ENTRY_URL = `${
1617
location.protocol === 'https:' ? 'wss:' : 'ws:'
17-
}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${getBrowserState().config.name || ''}`
18+
}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&rpcId=${RPC_ID}&sessionId=${getBrowserState().sessionId}&projectName=${getBrowserState().config.name || ''}&method=${METHOD}`
1819

1920
let setCancel = (_: CancelReason) => {}
2021
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
@@ -27,6 +27,7 @@
2727
sessionId: { __VITEST_SESSION_ID__ },
2828
testerId: { __VITEST_TESTER_ID__ },
2929
provider: { __VITEST_PROVIDER__ },
30+
method: { __VITEST_METHOD__ },
3031
providedContext: { __VITEST_PROVIDED_CONTEXT__ },
3132
};
3233

packages/browser/src/client/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface BrowserRunnerState {
7474
iframeId?: string
7575
sessionId: string
7676
testerId: string
77+
method: 'run' | 'collect'
7778
runTests?: (tests: string[]) => Promise<void>
7879
createTesters?: (files: string[]) => Promise<void>
7980
cdp?: {

packages/browser/src/node/rpc.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
5050
)
5151
}
5252

53+
const method = searchParams.get('method') as 'run' | 'collect'
54+
if (method !== 'run' && method !== 'collect') {
55+
return error(
56+
new Error(`[vitest] Method query in ${request.url} is invalid. Method should be either "run" or "collect".`),
57+
)
58+
}
59+
5360
if (type === 'orchestrator') {
5461
const session = vitest._browserSessions.getSession(sessionId)
5562
// it's possible the session was already resolved by the preview provider
@@ -67,7 +74,7 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
6774
wss.handleUpgrade(request, socket, head, (ws) => {
6875
wss.emit('connection', ws, request)
6976

70-
const rpc = setupClient(project, rpcId, ws)
77+
const rpc = setupClient(project, rpcId, ws, method)
7178
const state = project.browser!.state as BrowserServerState
7279
const clients = type === 'tester' ? state.testers : state.orchestrators
7380
clients.set(rpcId, rpc)
@@ -96,7 +103,7 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
96103
}
97104
}
98105

99-
function setupClient(project: TestProject, rpcId: string, ws: WebSocket) {
106+
function setupClient(project: TestProject, rpcId: string, ws: WebSocket, method: 'run' | 'collect') {
100107
const mockResolver = new ServerMockResolver(globalServer.vite, {
101108
moduleDirectories: project.config.server?.deps?.moduleDirectories,
102109
})
@@ -111,19 +118,39 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
111118
vitest.state.catchError(error, type)
112119
},
113120
async onQueued(file) {
114-
await vitest._testRun.enqueued(project, file)
121+
if (method === 'collect') {
122+
vitest.state.collectFiles(project, [file])
123+
}
124+
else {
125+
await vitest._testRun.enqueued(project, file)
126+
}
115127
},
116128
async onCollected(files) {
117-
await vitest._testRun.collected(project, files)
129+
if (method === 'collect') {
130+
vitest.state.collectFiles(project, files)
131+
}
132+
else {
133+
await vitest._testRun.collected(project, files)
134+
}
118135
},
119136
async onTaskUpdate(packs, events) {
120-
await vitest._testRun.updated(packs, events)
137+
if (method === 'collect') {
138+
vitest.state.updateTasks(packs)
139+
}
140+
else {
141+
await vitest._testRun.updated(packs, events)
142+
}
121143
},
122144
onAfterSuiteRun(meta) {
123145
vitest.coverageProvider?.onAfterSuiteRun(meta)
124146
},
125-
sendLog(log) {
126-
return vitest._testRun.log(log)
147+
async sendLog(log) {
148+
if (method === 'collect') {
149+
vitest.state.updateUserLog(log)
150+
}
151+
else {
152+
await vitest._testRun.log(log)
153+
}
127154
},
128155
resolveSnapshotPath(testPath) {
129156
return vitest.snapshot.resolvePath<ResolveSnapshotPathHandlerContext>(testPath, {

packages/browser/src/node/serverOrchestrator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function resolveOrchestrator(
3636
__VITEST_VITE_CONFIG__: JSON.stringify({
3737
root: browserProject.vite.config.root,
3838
}),
39+
__VITEST_METHOD__: JSON.stringify(session?.method || 'run'),
3940
__VITEST_FILES__: JSON.stringify(files),
4041
__VITEST_TYPE__: '"orchestrator"',
4142
__VITEST_SESSION_ID__: JSON.stringify(sessionId),

packages/browser/src/node/serverTester.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ export async function resolveTester(
5757
: await globalServer.injectorJs
5858

5959
const injector = replacer(injectorJs, {
60-
__VITEST_PROVIDER__: JSON.stringify(project.browser!.provider!.name),
60+
__VITEST_PROVIDER__: JSON.stringify(project.browser!.provider.name),
6161
__VITEST_CONFIG__: JSON.stringify(browserProject.wrapSerializedConfig()),
6262
__VITEST_FILES__: JSON.stringify(files),
6363
__VITEST_VITE_CONFIG__: JSON.stringify({
6464
root: browserProject.vite.config.root,
6565
}),
6666
__VITEST_TYPE__: '"tester"',
67+
__VITEST_METHOD__: JSON.stringify(method),
6768
__VITEST_SESSION_ID__: JSON.stringify(sessionId),
6869
__VITEST_TESTER_ID__: JSON.stringify(crypto.randomUUID()),
6970
__VITEST_PROVIDED_CONTEXT__: JSON.stringify(stringify(project.getProvidedContext())),

0 commit comments

Comments
 (0)