Skip to content

Commit

Permalink
feat(browser): add "init" command for browser tests (#5960)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jun 25, 2024
1 parent e0f45cb commit 49e973c
Show file tree
Hide file tree
Showing 14 changed files with 1,100 additions and 210 deletions.
23 changes: 21 additions & 2 deletions docs/guide/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ This page provides information about the experimental browser mode feature in th

## Installation

By default, Browser Mode doesn't require any additional E2E provider to run tests locally because it reuses your existing browser.
For easier setup, you can use `vitest init browser` command to install required dependencies and create browser configuration.

::: code-group
```bash [npm]
npx vitest init browser
```
```bash [yarn]
yarn exec vitest init browser
```
```bash [pnpm]
pnpx vitest init browser
```
```bash [bun]
bunx vitest init browser
```
:::

### Manual Installation

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.

::: code-group
```bash [npm]
Expand Down Expand Up @@ -997,7 +1016,7 @@ We recommend using `testing-library` packages depending on your framework:
- [`@testing-library/svelte`](https://testing-library.com/docs/svelte-testing-library/intro) to render [svelte](https://svelte.dev) components
- [`@testing-library/react`](https://testing-library.com/docs/react-testing-library/intro) to render [react](https://react.dev) components
- [`@testing-library/preact`](https://testing-library.com/docs/preact-testing-library/intro) to render [preact](https://preactjs.com) components
- [`@testing-library/solid`](https://testing-library.com/docs/solid-testing-library/intro) to render [solid](https://www.solidjs.com) components
- [`solid-testing-library`](https://testing-library.com/docs/solid-testing-library/intro) to render [solid](https://www.solidjs.com) components
- [`@marko/testing-library`](https://testing-library.com/docs/marko-testing-library/intro) to render [marko](https://markojs.com) components

::: warning
Expand Down
9 changes: 9 additions & 0 deletions packages/browser/src/client/channel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CancelReason } from '@vitest/runner'
import { getBrowserState } from './utils'

export interface IframeDoneEvent {
Expand Down Expand Up @@ -59,6 +60,13 @@ export interface IframeMockInvalidateEvent {
type: 'mock:invalidate'
}

export interface GlobalChannelTestRunCanceledEvent {
type: 'cancel'
reason: CancelReason
}

export type GlobalChannelIncomingEvent = GlobalChannelTestRunCanceledEvent

export type IframeChannelIncomingEvent =
| IframeViewportEvent
| IframeErrorEvent
Expand All @@ -81,6 +89,7 @@ export type IframeChannelEvent =
export const channel = new BroadcastChannel(
`vitest:${getBrowserState().contextId}`,
)
export const globalChannel = new BroadcastChannel('vitest:global')

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

0 comments on commit 49e973c

Please sign in to comment.