Skip to content

Commit 542b862

Browse files
authored
Merge branch 'main' into fix/use-monotonic-clock-for-timeout-guard
2 parents 7101a11 + 228067e commit 542b862

42 files changed

Lines changed: 1751 additions & 871 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070

7171
- name: Get changed files
7272
id: changed-files
73-
uses: tj-actions/changed-files@7dee1b0c1557f278e5c7dc244927139d78c0e22a # v47.0.4
73+
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
7474
with:
7575
files: |
7676
docs/**

docs/api/advanced/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This is an advanced API. If you just want to [run tests](/guide/), you probably
1111
This guide assumes you know how to work with [Vite plugins](https://vite.dev/guide/api-plugin.html).
1212
:::
1313

14-
Vitest supports a `configureVitest` [plugin](https://vite.dev/guide/api-plugin.html) hook hook since version 3.1.
14+
Vitest supports a `configureVitest` [plugin](https://vite.dev/guide/api-plugin.html) hook since version 3.1.
1515

1616
::: code-group
1717
```ts [only vitest]

docs/api/browser/react.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export function render(
3939
): Promise<RenderResult>
4040
```
4141

42+
The `render` function records a `react.render` trace mark, visible in the [Trace View](/guide/browser/trace-view).
43+
4244
:::warning
4345
Note that `render` is asynchronous, unlike in other packages. This is to support [`Suspense`](https://react.dev/reference/react/Suspense) correctly.
4446

@@ -154,6 +156,8 @@ This method is a shortcut for `console.log(prettyDOM(baseElement))`. It will pri
154156
function rerender(ui: React.ReactNode): Promise<void>
155157
```
156158

159+
Also records a `react.rerender` trace mark in the [Trace View](/guide/browser/trace-view).
160+
157161
It is better if you test the component that's doing the prop updating to ensure that the props are being updated correctly to avoid relying on implementation details in your tests. That said, if you'd prefer to update the props of a rendered component in your test, this function can be used to update props of the rendered component.
158162

159163
```jsx
@@ -171,6 +175,8 @@ await rerender(<NumberDisplay number={2} />)
171175
function unmount(): Promise<void>
172176
```
173177

178+
Also records a `react.unmount` trace mark in the [Trace View](/guide/browser/trace-view).
179+
174180
This will cause the rendered component to be unmounted. This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks).
175181

176182
```jsx

docs/api/browser/svelte.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { expect, test } from 'vitest'
1212
import Component from './Component.svelte'
1313

1414
test('counter button increments the count', async () => {
15-
const screen = render(Component, {
15+
const screen = await render(Component, {
1616
initialCount: 1,
1717
})
1818

@@ -39,15 +39,26 @@ export function render<C extends Component>(
3939
Component: ComponentImport<C>,
4040
options?: ComponentOptions<C>,
4141
renderOptions?: SetupOptions
42-
): RenderResult<C>
42+
): RenderResult<C> & PromiseLike<RenderResult<C>>
4343
```
4444

45+
The `render` function records a `svelte.render` trace mark, visible in the [Trace View](/guide/browser/trace-view).
46+
47+
::: warning
48+
Synchronous usage of `render` is deprecated and will be removed in the next major version. Please always `await` the result:
49+
50+
```ts
51+
const screen = render(Component) // [!code --]
52+
const screen = await render(Component) // [!code ++]
53+
```
54+
:::
55+
4556
### Options
4657

4758
The `render` function supports either options that you can pass down to [`mount`](https://svelte.dev/docs/svelte/imperative-component-api#mount) or props directly:
4859

4960
```ts
50-
const screen = render(Component, {
61+
const screen = await render(Component, {
5162
props: { // [!code --]
5263
initialCount: 1, // [!code --]
5364
}, // [!code --]
@@ -68,7 +79,7 @@ For example, if you are unit testing a `tbody` element, it cannot be a child of
6879
```ts
6980
const table = document.createElement('table')
7081
71-
const screen = render(TableBody, {
82+
const screen = await render(TableBody, {
7283
props,
7384
// ⚠️ appending the element to `body` manually before rendering
7485
target: document.body.appendChild(table),
@@ -86,7 +97,7 @@ If the `target` is specified, then this defaults to that, otherwise this default
8697
In addition to documented return value, the `render` function also returns all available [locators](/api/browser/locators) relative to the [`baseElement`](#baseelement), including [custom ones](/api/browser/locators#custom-locators).
8798

8899
```ts
89-
const screen = render(TableBody, props)
100+
const screen = await render(TableBody, props)
90101
91102
await screen.getByRole('link', { name: 'Expand' }).click()
92103
```
@@ -104,7 +115,7 @@ If you find yourself using `container` to query for rendered elements then you s
104115
The mounted Svelte component instance. You can use this to access component methods and properties if needed.
105116

106117
```ts
107-
const { component } = render(Counter, {
118+
const { component } = await render(Counter, {
108119
initialCount: 0,
109120
})
110121
@@ -118,7 +129,7 @@ The [locator](/api/browser/locators) of your `container`. It is useful to use qu
118129
```ts
119130
import { render } from 'vitest-browser-svelte'
120131
121-
const { locator } = render(NumberDisplay, {
132+
const { locator } = await render(NumberDisplay, {
122133
number: 2,
123134
})
124135
@@ -139,15 +150,15 @@ This method is a shortcut for `console.log(prettyDOM(baseElement))`. It will pri
139150
#### rerender
140151

141152
```ts
142-
function rerender(props: Partial<ComponentProps<T>>): void
153+
function rerender(props: Partial<ComponentProps<T>>): Promise<void>
143154
```
144155

145-
Updates the component's props and waits for Svelte to apply the changes. Use this to test how your component responds to prop changes.
156+
Updates the component's props and waits for Svelte to apply the changes. Use this to test how your component responds to prop changes. Also records a `svelte.rerender` trace mark in the [Trace View](/guide/browser/trace-view).
146157

147158
```ts
148159
import { render } from 'vitest-browser-svelte'
149160
150-
const { rerender } = render(NumberDisplay, {
161+
const { rerender } = await render(NumberDisplay, {
151162
number: 1,
152163
})
153164
@@ -158,16 +169,20 @@ await rerender({ number: 2 })
158169
#### unmount
159170

160171
```ts
161-
function unmount(): void
172+
function unmount(): Promise<void>
162173
```
163174

164-
Unmount and destroy the Svelte component. This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks).
175+
Unmount and destroy the Svelte component. Also records a `svelte.unmount` trace mark in the [Trace View](/guide/browser/trace-view). This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks).
176+
177+
::: warning
178+
Synchronous usage of `unmount` is deprecated and will be removed in the next major version. Please always `await` the result.
179+
:::
165180

166181
```ts
167182
import { render } from 'vitest-browser-svelte'
168183
169-
const { container, unmount } = render(Component)
170-
unmount()
184+
const { container, unmount } = await render(Component)
185+
await unmount()
171186
// your component has been unmounted and now: container.innerHTML === ''
172187
```
173188

@@ -193,7 +208,7 @@ locators.extend({
193208
},
194209
})
195210
196-
const screen = render(Component)
211+
const screen = await render(Component)
197212
await expect.element(
198213
screen.getByArticleTitle('Hello World')
199214
).toBeVisible()
@@ -211,7 +226,7 @@ import { expect, test } from 'vitest'
211226
import SubjectTest from './basic-snippet.test.svelte'
212227
213228
test('basic snippet', async () => {
214-
const screen = render(SubjectTest)
229+
const screen = await render(SubjectTest)
215230
216231
const heading = screen.getByRole('heading')
217232
const child = heading.getByTestId('child')
@@ -250,7 +265,7 @@ import { expect, test } from 'vitest'
250265
import Subject from './complex-snippet.svelte'
251266
252267
test('renders greeting in message snippet', async () => {
253-
const screen = render(Subject, {
268+
const screen = await render(Subject, {
254269
name: 'Alice',
255270
message: createRawSnippet(greeting => ({
256271
render: () => `<span data-testid="message">${greeting()}</span>`,

docs/api/browser/vue.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { expect, test } from 'vitest'
1212
import Component from './Component.vue'
1313

1414
test('counter button increments the count', async () => {
15-
const screen = render(Component, {
15+
const screen = await render(Component, {
1616
props: {
1717
initialCount: 1,
1818
}
@@ -40,9 +40,20 @@ The package exposes two entry points: `vitest-browser-vue` and `vitest-browser-v
4040
export function render(
4141
component: Component,
4242
options?: ComponentRenderOptions,
43-
): RenderResult
43+
): RenderResult & PromiseLike<RenderResult>
4444
```
4545

46+
The `render` function records a `vue.render` trace mark, visible in the [Trace View](/guide/browser/trace-view).
47+
48+
::: warning
49+
Synchronous usage of `render` is deprecated and will be removed in the next major version. Please always `await` the result:
50+
51+
```ts
52+
const screen = render(Component) // [!code --]
53+
const screen = await render(Component) // [!code ++]
54+
```
55+
:::
56+
4657
### Options
4758

4859
The `render` function supports all [`mount` options](https://test-utils.vuejs.org/api/#mount) from `@vue/test-utils` (except `attachTo` - use `container` instead). In addition to them, there are also `container` and `baseElement`.
@@ -56,7 +67,7 @@ For example, if you are unit testing a `tbody` element, it cannot be a child of
5667
```js
5768
const table = document.createElement('table')
5869
59-
const { container } = render(TableBody, {
70+
const { container } = await render(TableBody, {
6071
props,
6172
// ⚠️ appending the element to `body` manually before rendering
6273
container: document.body.appendChild(table),
@@ -72,7 +83,7 @@ If the `container` is specified, then this defaults to that, otherwise this defa
7283
In addition to documented return value, the `render` function also returns all available [locators](/api/browser/locators) relative to the [`baseElement`](#baseelement), including [custom ones](/api/browser/locators#custom-locators).
7384

7485
```ts
75-
const screen = render(TableBody, { props })
86+
const screen = await render(TableBody, { props })
7687
7788
await screen.getByRole('link', { name: 'Expand' }).click()
7889
```
@@ -102,7 +113,7 @@ The [locator](/api/browser/locators) of your `container`. It is useful to use qu
102113
```js
103114
import { render } from 'vitest-browser-vue'
104115
105-
const { locator } = render(NumberDisplay, {
116+
const { locator } = await render(NumberDisplay, {
106117
props: { number: 2 }
107118
})
108119
@@ -125,27 +136,37 @@ This method is a shortcut for `console.log(prettyDOM(baseElement))`. It will pri
125136
#### rerender
126137

127138
```ts
128-
function rerender(props: Partial<Props>): void
139+
function rerender(props: Partial<Props>): void & PromiseLike<void>
129140
```
130141

142+
Also records a `vue.rerender` trace mark in the [Trace View](/guide/browser/trace-view).
143+
131144
It is better if you test the component that's doing the prop updating to ensure that the props are being updated correctly to avoid relying on implementation details in your tests. That said, if you'd prefer to update the props of a rendered component in your test, this function can be used to update props of the rendered component.
132145

146+
::: warning
147+
Synchronous usage of `rerender` is deprecated and will be removed in the next major version. Please always `await` the result.
148+
:::
149+
133150
```js
134151
import { render } from 'vitest-browser-vue'
135152
136-
const { rerender } = render(NumberDisplay, { props: { number: 1 } })
153+
const { rerender } = await render(NumberDisplay, { props: { number: 1 } })
137154
138155
// re-render the same component with different props
139-
rerender({ number: 2 })
156+
await rerender({ number: 2 })
140157
```
141158

142159
#### unmount
143160

144161
```ts
145-
function unmount(): void
162+
function unmount(): void & PromiseLike<void>
146163
```
147164

148-
This will cause the rendered component to be unmounted. This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks).
165+
This will cause the rendered component to be unmounted. Also records a `vue.unmount` trace mark in the [Trace View](/guide/browser/trace-view). This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks).
166+
167+
::: warning
168+
Synchronous usage of `unmount` is deprecated and will be removed in the next major version. Please always `await` the result.
169+
:::
149170

150171
#### emitted
151172

@@ -182,7 +203,7 @@ locators.extend({
182203
},
183204
})
184205
185-
const screen = render(Component)
206+
const screen = await render(Component)
186207
await expect.element(
187208
screen.getByArticleTitle('Hello World')
188209
).toBeVisible()

docs/config/reporters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Note that the [coverage](/guide/coverage) feature uses a different [`coverage.re
4242
- [`tap-flat`](/guide/reporters#tap-flat-reporter)
4343
- [`hanging-process`](/guide/reporters#hanging-process-reporter)
4444
- [`github-actions`](/guide/reporters#github-actions-reporter)
45+
- [`agent`](/guide/reporters#agent-reporter)
4546
- [`blob`](/guide/reporters#blob-reporter)
4647
4748
## Example

docs/guide/browser/visual-regression-testing.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ screenshots should use the service.
606606

607607
The cleanest approach is using [Test Projects](/guide/projects):
608608

609-
610609
```ts [vitest.config.ts]
611610
import { env } from 'node:process'
612611
import { defineConfig } from 'vitest/config'
@@ -663,7 +662,6 @@ export default defineConfig({
663662
})
664663
```
665664

666-
667665
Follow the [official guide to create a Playwright Workspace](https://learn.microsoft.com/en-us/azure/app-testing/playwright-workspaces/quickstart-run-end-to-end-tests?tabs=playwrightcli&pivots=playwright-test-runner#create-a-workspace).
668666

669667
Once your workspace is created, configure Vitest to use it:

docs/guide/cli-generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Hide logs for skipped tests
102102
- **CLI:** `--reporter <name>`
103103
- **Config:** [reporters](/config/reporters)
104104

105-
Specify reporters (default, blob, verbose, dot, json, tap, tap-flat, junit, tree, hanging-process, github-actions)
105+
Specify reporters (default, agent, blob, verbose, dot, json, tap, tap-flat, junit, tree, hanging-process, github-actions)
106106

107107
### outputFile
108108

docs/guide/cli.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,3 @@ Merges every blob report located in the specified folder (`.vitest-reports` by d
237237
```sh
238238
vitest --merge-reports --reporter=junit
239239
```
240-

docs/guide/reporters.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ This example will write separate JSON and XML reports as well as printing a verb
9898

9999
By default (i.e. if no reporter is specified), Vitest will display summary of running tests and their status at the bottom. Once a suite passes, its status will be reported on top of the summary.
100100

101+
::: tip
102+
When Vitest detects it is running inside an AI coding agent, the [`agent`](#agent-reporter) reporter is used instead to reduce output and minimize token usage. You can override this by explicitly configuring the [`reporters`](/config/reporters) option.
103+
:::
104+
101105
You can disable the summary by configuring the reporter:
102106

103107
:::code-group
@@ -637,6 +641,26 @@ export default defineConfig({
637641
})
638642
```
639643

644+
### Agent Reporter
645+
646+
Outputs a minimal report optimized for AI coding assistants and LLM-based workflows. Only failed tests and their error messages are displayed. Console logs from passing tests and the summary section are suppressed to reduce token usage.
647+
648+
This reporter is automatically enabled when no `reporters` option is configured and Vitest detects it is running inside an AI coding agent. If you configure custom reporters, you can explicitly add `agent`:
649+
650+
:::code-group
651+
```bash [CLI]
652+
npx vitest --reporter=agent
653+
```
654+
655+
```ts [vitest.config.ts]
656+
export default defineConfig({
657+
test: {
658+
reporters: ['agent']
659+
},
660+
})
661+
```
662+
:::
663+
640664
### Blob Reporter
641665

642666
Stores test results on the machine so they can be later merged using [`--merge-reports`](/guide/cli#merge-reports) command.

0 commit comments

Comments
 (0)