Skip to content

Commit 49e973c

Browse files
authored
feat(browser): add "init" command for browser tests (#5960)
1 parent e0f45cb commit 49e973c

File tree

14 files changed

+1100
-210
lines changed

14 files changed

+1100
-210
lines changed

docs/guide/browser.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,26 @@ This page provides information about the experimental browser mode feature in th
88

99
## Installation
1010

11-
By default, Browser Mode doesn't require any additional E2E provider to run tests locally because it reuses your existing browser.
11+
For easier setup, you can use `vitest init browser` command to install required dependencies and create browser configuration.
12+
13+
::: code-group
14+
```bash [npm]
15+
npx vitest init browser
16+
```
17+
```bash [yarn]
18+
yarn exec vitest init browser
19+
```
20+
```bash [pnpm]
21+
pnpx vitest init browser
22+
```
23+
```bash [bun]
24+
bunx vitest init browser
25+
```
26+
:::
27+
28+
### Manual Installation
29+
30+
You can also install packages manually. By default, Browser Mode doesn't require any additional E2E provider to run tests locally because it reuses your existing browser.
1231

1332
::: code-group
1433
```bash [npm]
@@ -997,7 +1016,7 @@ We recommend using `testing-library` packages depending on your framework:
9971016
- [`@testing-library/svelte`](https://testing-library.com/docs/svelte-testing-library/intro) to render [svelte](https://svelte.dev) components
9981017
- [`@testing-library/react`](https://testing-library.com/docs/react-testing-library/intro) to render [react](https://react.dev) components
9991018
- [`@testing-library/preact`](https://testing-library.com/docs/preact-testing-library/intro) to render [preact](https://preactjs.com) components
1000-
- [`@testing-library/solid`](https://testing-library.com/docs/solid-testing-library/intro) to render [solid](https://www.solidjs.com) components
1019+
- [`solid-testing-library`](https://testing-library.com/docs/solid-testing-library/intro) to render [solid](https://www.solidjs.com) components
10011020
- [`@marko/testing-library`](https://testing-library.com/docs/marko-testing-library/intro) to render [marko](https://markojs.com) components
10021021

10031022
::: warning

packages/browser/src/client/channel.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { CancelReason } from '@vitest/runner'
12
import { getBrowserState } from './utils'
23

34
export interface IframeDoneEvent {
@@ -59,6 +60,13 @@ export interface IframeMockInvalidateEvent {
5960
type: 'mock:invalidate'
6061
}
6162

63+
export interface GlobalChannelTestRunCanceledEvent {
64+
type: 'cancel'
65+
reason: CancelReason
66+
}
67+
68+
export type GlobalChannelIncomingEvent = GlobalChannelTestRunCanceledEvent
69+
6270
export type IframeChannelIncomingEvent =
6371
| IframeViewportEvent
6472
| IframeErrorEvent
@@ -81,6 +89,7 @@ export type IframeChannelEvent =
8189
export const channel = new BroadcastChannel(
8290
`vitest:${getBrowserState().contextId}`,
8391
)
92+
export const globalChannel = new BroadcastChannel('vitest:global')
8493

8594
export function waitForChannel(event: IframeChannelOutgoingEvent['type']) {
8695
return new Promise<void>((resolve) => {

0 commit comments

Comments
 (0)