Skip to content

Commit 118ebb0

Browse files
authored
Merge branch 'main' into fix-inlinesnapshot
2 parents 66a124f + e2c570b commit 118ebb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1798
-2026
lines changed

docs/api/vi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ Mocking `nextTick` is not supported when running Vitest inside `node:child_proce
818818
The implementation is based internally on [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers).
819819

820820
::: tip
821-
`vi.useFakeTimers()` does not automatically mock `process.nextTick`.
822-
But you can enable it by specifying the option in `toFake` argument: `vi.useFakeTimers({ toFake: ['nextTick'] })`.
821+
`vi.useFakeTimers()` does not automatically mock `process.nextTick` and `queueMicrotask`.
822+
But you can enable it by specifying the option in `toFake` argument: `vi.useFakeTimers({ toFake: ['nextTick', 'queueMicrotask'] })`.
823823
:::
824824

825825
### vi.isFakeTimers {#vi-isfaketimers}

docs/config/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,7 @@ Installs fake timers with the specified Unix epoch.
23452345
#### fakeTimers.toFake
23462346

23472347
- **Type:** `('setTimeout' | 'clearTimeout' | 'setImmediate' | 'clearImmediate' | 'setInterval' | 'clearInterval' | 'Date' | 'nextTick' | 'hrtime' | 'requestAnimationFrame' | 'cancelAnimationFrame' | 'requestIdleCallback' | 'cancelIdleCallback' | 'performance' | 'queueMicrotask')[]`
2348-
- **Default:** everything available globally except `nextTick`
2348+
- **Default:** everything available globally except `nextTick` and `queueMicrotask`
23492349

23502350
An array with names of global methods and APIs to fake.
23512351

docs/guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Vitest will prompt you to install certain dependencies if they are not already i
234234

235235
## IDE Integrations
236236

237-
We also provided a official extension for Visual Studio Code to enhance your testing experience with Vitest.
237+
We also provided an official extension for Visual Studio Code to enhance your testing experience with Vitest.
238238

239239
[Install from VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=vitest.explorer)
240240

docs/guide/mocking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ afterAll(() => server.close())
473473
afterEach(() => server.resetHandlers())
474474
```
475475

476-
```js [GrapQL Setup]
476+
```js [GraphQL Setup]
477477
import { afterAll, afterEach, beforeAll } from 'vitest'
478478
import { setupServer } from 'msw/node'
479479
import { graphql, HttpResponse } from 'msw'

docs/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"generate-pwa-icons": "pwa-assets-generator"
1515
},
1616
"dependencies": {
17-
"@vueuse/core": "^12.5.0",
17+
"@vueuse/core": "^12.7.0",
1818
"vue": "^3.5.12"
1919
},
2020
"devDependencies": {
21-
"@iconify-json/carbon": "^1.2.6",
21+
"@iconify-json/carbon": "^1.2.7",
2222
"@iconify-json/logos": "^1.2.4",
2323
"@shikijs/transformers": "^1.29.2",
2424
"@shikijs/vitepress-twoslash": "^1.29.2",
@@ -27,13 +27,13 @@
2727
"@vite-pwa/vitepress": "^0.5.3",
2828
"@vitejs/plugin-vue": "^5.2.1",
2929
"https-localhost": "^4.7.1",
30-
"tinyglobby": "^0.2.10",
30+
"tinyglobby": "^0.2.12",
3131
"unocss": "^0.65.4",
3232
"unplugin-vue-components": "^0.28.0",
3333
"vite": "^5.2.8",
3434
"vite-plugin-pwa": "^0.21.1",
3535
"vitepress": "^1.6.3",
36-
"vitepress-plugin-group-icons": "^1.3.5",
36+
"vitepress-plugin-group-icons": "^1.3.6",
3737
"vitepress-plugin-tabs": "^0.6.0",
3838
"workbox-window": "^7.3.0"
3939
}

package.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@vitest/monorepo",
33
"type": "module",
4-
"version": "3.0.5",
4+
"version": "3.0.7",
55
"private": true,
6-
"packageManager": "pnpm@9.15.5",
6+
"packageManager": "pnpm@10.4.1",
77
"description": "Next generation testing framework powered by Vite",
88
"engines": {
99
"node": "^18.0.0 || >=20.0.0"
@@ -42,25 +42,25 @@
4242
"@rollup/plugin-commonjs": "^28.0.2",
4343
"@rollup/plugin-json": "^6.1.0",
4444
"@rollup/plugin-node-resolve": "^16.0.0",
45-
"@types/node": "^22.13.1",
45+
"@types/node": "^22.13.5",
4646
"@types/ws": "^8.5.14",
4747
"@vitest/browser": "workspace:*",
4848
"@vitest/coverage-istanbul": "workspace:*",
4949
"@vitest/coverage-v8": "workspace:*",
5050
"@vitest/ui": "workspace:*",
51-
"bumpp": "^10.0.2",
51+
"bumpp": "^10.0.3",
5252
"changelogithub": "^13.12.1",
5353
"esbuild": "^0.25.0",
54-
"eslint": "^9.20.0",
54+
"eslint": "^9.21.0",
5555
"magic-string": "^0.30.17",
56-
"pathe": "^2.0.2",
56+
"pathe": "^2.0.3",
5757
"rimraf": "^6.0.1",
58-
"rollup": "^4.34.6",
58+
"rollup": "^4.34.8",
5959
"rollup-plugin-dts": "^6.1.1",
6060
"rollup-plugin-esbuild": "^6.2.0",
61-
"rollup-plugin-license": "^3.5.3",
62-
"tinyglobby": "^0.2.10",
63-
"tsx": "^4.19.2",
61+
"rollup-plugin-license": "^3.6.0",
62+
"tinyglobby": "^0.2.12",
63+
"tsx": "^4.19.3",
6464
"typescript": "^5.7.3",
6565
"vite": "^6.0.11",
6666
"vitest": "workspace:*",
@@ -88,6 +88,17 @@
8888
"@types/[email protected]": "patches/@[email protected]",
8989
9090
91-
}
91+
},
92+
"onlyBuiltDependencies": [
93+
"@sveltejs/kit",
94+
"@swc/core",
95+
"edgedriver",
96+
"esbuild",
97+
"geckodriver",
98+
"msw",
99+
"sharp",
100+
"svelte-preprocess",
101+
"vue-demi"
102+
]
92103
}
93104
}

packages/browser/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vitest/browser",
33
"type": "module",
4-
"version": "3.0.5",
4+
"version": "3.0.7",
55
"description": "Browser running for Vitest",
66
"license": "MIT",
77
"funding": "https://opencollective.com/vitest",
@@ -60,6 +60,7 @@
6060
"*.d.ts",
6161
"context.js",
6262
"dist",
63+
"dummy.js",
6364
"providers"
6465
],
6566
"scripts": {
@@ -73,7 +74,7 @@
7374
"peerDependencies": {
7475
"playwright": "*",
7576
"vitest": "workspace:*",
76-
"webdriverio": "*"
77+
"webdriverio": "^7.0.0 || ^8.0.0 || ^9.0.0"
7778
},
7879
"peerDependenciesMeta": {
7980
"playwright": {
@@ -87,33 +88,33 @@
8788
}
8889
},
8990
"dependencies": {
90-
"@testing-library/dom": "^10.4.0",
9191
"@testing-library/user-event": "^14.6.1",
9292
"@vitest/mocker": "workspace:*",
9393
"@vitest/utils": "workspace:*",
9494
"magic-string": "^0.30.17",
95-
"msw": "^2.7.0",
96-
"sirv": "^3.0.0",
95+
"msw": "^2.7.3",
96+
"sirv": "^3.0.1",
9797
"tinyrainbow": "^2.0.0",
98-
"ws": "^8.18.0"
98+
"ws": "^8.18.1"
9999
},
100100
"devDependencies": {
101101
"@testing-library/jest-dom": "^6.6.3",
102102
"@types/ws": "^8.5.14",
103103
"@vitest/runner": "workspace:*",
104104
"@vitest/ui": "workspace:*",
105105
"@vitest/ws-client": "workspace:*",
106-
"@wdio/protocols": "^8.40.3",
106+
"@wdio/protocols": "^9.7.0",
107+
"@wdio/types": "^9.9.0",
107108
"birpc": "0.2.19",
108-
"flatted": "^3.3.2",
109+
"flatted": "^3.3.3",
109110
"ivya": "^1.1.1",
110111
"mime": "^4.0.6",
111-
"pathe": "^2.0.2",
112+
"pathe": "^2.0.3",
112113
"periscopic": "^4.0.2",
113114
"playwright": "^1.50.1",
114115
"playwright-core": "^1.50.1",
115116
"safaridriver": "^1.0.0",
116117
"vitest": "workspace:*",
117-
"webdriverio": "^8.41.0"
118+
"webdriverio": "^9.10.0"
118119
}
119120
}

packages/browser/providers/webdriverio.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import type { RemoteOptions, ClickOptions, DragAndDropOptions } from 'webdriverio'
1+
import type { remote, ClickOptions, DragAndDropOptions } from 'webdriverio'
22
import '../matchers.js'
33
import type {} from "vitest/node"
44

55
declare module 'vitest/node' {
6-
export interface BrowserProviderOptions extends Partial<RemoteOptions> {}
6+
export interface BrowserProviderOptions extends Partial<
7+
Parameters<typeof remote>[0]
8+
> {}
79

810
export interface UserEventClickOptions extends ClickOptions {}
911

packages/browser/src/client/tester/context.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Options as TestingLibraryOptions, UserEvent as TestingLibraryUserEvent } from '@testing-library/user-event'
2-
import type { BrowserRPC } from '@vitest/browser/client'
32
import type { RunnerTask } from 'vitest'
43
import type {
54
BrowserPage,
@@ -19,15 +18,11 @@ import { convertElementToCssSelector, ensureAwaited, getBrowserState, getWorkerS
1918
const state = () => getWorkerState()
2019
// @ts-expect-error not typed global
2120
const provider = __vitest_browser_runner__.provider
22-
function filepath() {
23-
return getWorkerState().filepath || getWorkerState().current?.file?.filepath || undefined
24-
}
25-
const rpc = () => getWorkerState().rpc as any as BrowserRPC
2621
const sessionId = getBrowserState().sessionId
2722
const channel = new BroadcastChannel(`vitest:${sessionId}`)
2823

2924
function triggerCommand<T>(command: string, ...args: any[]) {
30-
return rpc().triggerCommand<T>(sessionId, command, filepath(), args)
25+
return getBrowserState().commands.triggerCommand<T>(command, args)
3126
}
3227

3328
export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent, options?: TestingLibraryOptions): UserEvent {
@@ -52,6 +47,10 @@ export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent
5247
return createUserEvent()
5348
},
5449
async cleanup() {
50+
// avoid cleanup rpc call if there is nothing to cleanup
51+
if (!keyboard.unreleased.length) {
52+
return
53+
}
5554
return ensureAwaited(async () => {
5655
await triggerCommand('__vitest_cleanup', keyboard)
5756
keyboard.unreleased = []
@@ -106,9 +105,7 @@ export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent
106105
})
107106
},
108107
tab(options: UserEventTabOptions = {}) {
109-
return ensureAwaited(() => {
110-
return triggerCommand('__vitest_tab', options)
111-
})
108+
return ensureAwaited(() => triggerCommand('__vitest_tab', options))
112109
},
113110
async keyboard(text: string) {
114111
return ensureAwaited(async () => {

packages/browser/src/client/tester/locators/index.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { BrowserRPC } from '@vitest/browser/client'
21
import type {
32
LocatorByRoleOptions,
43
LocatorOptions,
@@ -8,8 +7,6 @@ import type {
87
UserEventFillOptions,
98
UserEventHoverOptions,
109
} from '@vitest/browser/context'
11-
import type { WorkerGlobalState } from 'vitest'
12-
import type { BrowserRunnerState } from '../../utils'
1310
import { page, server } from '@vitest/browser/context'
1411
import {
1512
getByAltTextSelector,
@@ -22,7 +19,7 @@ import {
2219
Ivya,
2320
type ParsedSelector,
2421
} from 'ivya'
25-
import { ensureAwaited, getBrowserState, getWorkerState } from '../../utils'
22+
import { ensureAwaited, getBrowserState } from '../../utils'
2623
import { getElementError } from '../public-utils'
2724

2825
// we prefer using playwright locators because they are more powerful and support Shadow DOM
@@ -205,27 +202,10 @@ export abstract class Locator {
205202
return this.selector
206203
}
207204

208-
private get state(): BrowserRunnerState {
209-
return getBrowserState()
210-
}
211-
212-
private get worker(): WorkerGlobalState {
213-
return getWorkerState()
214-
}
215-
216-
private get rpc(): BrowserRPC {
217-
return this.worker.rpc as any as BrowserRPC
218-
}
219-
220205
protected triggerCommand<T>(command: string, ...args: any[]): Promise<T> {
221-
const filepath = this.worker.filepath
222-
|| this.worker.current?.file?.filepath
223-
|| undefined
224-
225-
return ensureAwaited(() => this.rpc.triggerCommand<T>(
226-
this.state.sessionId,
206+
const commands = getBrowserState().commands
207+
return ensureAwaited(() => commands.triggerCommand<T>(
227208
command,
228-
filepath,
229209
args,
230210
))
231211
}

0 commit comments

Comments
 (0)