Skip to content

Commit 0b26abb

Browse files
authored
Merge branch 'main' into fix/spaces-in-path
2 parents 794b3d4 + c594d4a commit 0b26abb

Some content is hidden

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

59 files changed

+1393
-452
lines changed

docs/.vitepress/theme/index.ts

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,44 @@ import '@shikijs/vitepress-twoslash/style.css'
1414
import 'virtual:group-icons.css'
1515

1616
if (inBrowser) {
17+
// redirect old hash links (e.g. /config/#reporters -> /config/reporters)
18+
// before hydration to avoid SSG hydration mismatch
19+
const redirect = getRedirectPath(new URL(location.href))
20+
if (redirect) {
21+
location.replace(redirect)
22+
}
1723
import('./pwa')
1824
}
1925

26+
function getRedirectPath(url: URL) {
27+
if (url.pathname === '/api/' || url.pathname === '/api' || url.pathname === '/api/index.html') {
28+
return '/api/test'
29+
}
30+
if (!url.hash) {
31+
return
32+
}
33+
34+
// /config/#reporters -> /config/reporters
35+
// /config/#coverage-provider -> /config/coverage#coverage-provider
36+
// /config/#browser.enabled -> /config/browser/enabled
37+
if (url.pathname === '/config' || url.pathname === '/config/' || url.pathname === '/config.html') {
38+
if (url.hash.startsWith('#browser.')) {
39+
const [page, ...hash] = url.hash.slice('#browser.'.length).toLowerCase().split('-')
40+
return `/config/browser/${page}${hash.length ? `#${[page, ...hash].join('-')}` : ''}`
41+
}
42+
const [page, ...hash] = url.hash.slice(1).toLowerCase().split('-')
43+
return `/config/${page}${hash.length ? `#${[page, ...hash].join('-')}` : ''}`
44+
}
45+
// /guide/browser/config#browser.locators-testidattribute -> /config/browser/locators#browser-locators-testidattribute
46+
if (url.pathname === '/guide/browser/config' || url.pathname === '/guide/browser/config/' || url.pathname === '/guide/browser/config.html') {
47+
const [page, ...hash] = url.hash.slice('#browser.'.length).toLowerCase().split('-')
48+
return `/config/browser/${page}${hash.length ? `#${[page, ...hash].join('-')}` : ''}`
49+
}
50+
}
51+
2052
export default {
2153
extends: VitestTheme as unknown as any,
22-
enhanceApp({ app, router }) {
23-
router.onBeforeRouteChange = (to) => {
24-
if (typeof location === 'undefined') {
25-
return true
26-
}
27-
const url = new URL(to, location.href)
28-
if (url.pathname === '/api/' || url.pathname === '/api' || url.pathname === '/api/index.html') {
29-
setTimeout(() => { router.go(`/api/test`) })
30-
return false
31-
}
32-
if (!url.hash) {
33-
return true
34-
}
35-
if (url.pathname === '/config' || url.pathname === '/config/' || url.pathname === '/config.html') {
36-
const [page, ...hash] = (url.hash.startsWith('#browser.') ? url.hash.slice(9) : url.hash.slice(1)).toLowerCase().split('-')
37-
setTimeout(() => { router.go(`/config/${page}${hash.length ? `#${[page, ...hash].join('-')}` : ''}`) })
38-
return false
39-
}
40-
if (url.pathname === '/guide/browser/config' || url.pathname === '/guide/browser/config/' || url.pathname === '/guide/browser/config.html') {
41-
const [page, ...hash] = url.hash.slice('#browser.'.length).toLowerCase().split('-')
42-
setTimeout(() => { router.go(`/config/browser/${page}${hash.length ? `#${[page, ...hash].join('-')}` : ''}`) })
43-
return false
44-
}
45-
}
54+
enhanceApp({ app }) {
4655
app.component('Version', Version)
4756
app.component('CRoot', CRoot)
4857
app.component('Experimental', Experimental)

docs/api/advanced/test-module.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ This is a Vite's [`DevEnvironment`](https://vite.dev/guide/api-environment) that
132132
## toTestSpecification <Version>4.1.0</Version> {#totestspecification}
133133
134134
```ts
135-
function toTestSpecification(): TestSpecification
135+
function toTestSpecification(testCases?: TestCase[]): TestSpecification
136136
```
137137

138138
Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test module.
139+
140+
It accepts an optional array of test cases that should be filtered.

docs/config/coverage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ To preview the coverage report in the output of [HTML reporter](/guide/reporters
9898
- **Available for providers:** `'v8' | 'istanbul'`
9999
- **CLI:** `--coverage.reporter=<reporter>`, `--coverage.reporter=<reporter1> --coverage.reporter=<reporter2>`
100100

101-
Coverage reporters to use. See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters. See [`@types/istanbul-reporter`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/276d95e4304b3670eaf6e8e5a7ea9e265a14e338/types/istanbul-reports/index.d.ts) for details about reporter specific options.
101+
Coverage reporters to use. See [istanbul documentation](https://istanbul.js.org/docs/advanced/alternative-reporters/) for detailed list of all reporters. See [`@types/istanbul-reports`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/276d95e4304b3670eaf6e8e5a7ea9e265a14e338/types/istanbul-reports/index.d.ts) for details about reporter specific options.
102102

103103
The reporter has three different types:
104104

docs/config/detectasyncleaks.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: detectAsyncLeaks | Config
3+
outline: deep
4+
---
5+
6+
# detectAsyncLeaks
7+
8+
- **Type:** `boolean`
9+
- **CLI:** `--detectAsyncLeaks`, `--detect-async-leaks`
10+
- **Default:** `false`
11+
12+
::: warning
13+
Enabling this option will make your tests run much slower. Use only when debugging or developing tests.
14+
:::
15+
16+
Detect asynchronous resources leaking from the test file.
17+
Uses [`node:async_hooks`](https://nodejs.org/api/async_hooks.html) to track creation of async resources. If a resource is not cleaned up, it will be logged after tests have finished.
18+
19+
For example if your code has `setTimeout` calls that execute the callback after tests have finished, you will see following error:
20+
21+
```sh
22+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Async Leaks 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
23+
24+
Timeout leaking in test/checkout-screen.test.tsx
25+
26|
26+
27| useEffect(() => {
27+
28| setTimeout(() => setWindowWidth(window.innerWidth), 150)
28+
| ^
29+
29| })
30+
30|
31+
```
32+
33+
To fix this, you'll need to make sure your code cleans the timeout properly:
34+
35+
```js
36+
useEffect(() => {
37+
setTimeout(() => setWindowWidth(window.innerWidth), 150) // [!code --]
38+
const timeout = setTimeout(() => setWindowWidth(window.innerWidth), 150) // [!code ++]
39+
40+
return function cleanup() { // [!code ++]
41+
clearTimeout(timeout) // [!code ++]
42+
} // [!code ++]
43+
})
44+
```

docs/guide/cli-generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,13 @@ Pass when no tests are found
464464

465465
Show the size of heap for each test when running in node
466466

467+
### detectAsyncLeaks
468+
469+
- **CLI:** `--detectAsyncLeaks`
470+
- **Config:** [detectAsyncLeaks](/config/detectasyncleaks)
471+
472+
Detect asynchronous resources leaking from the test file (default: `false`)
473+
467474
### allowOnly
468475

469476
- **CLI:** `--allowOnly`

docs/guide/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ tests/test1.test.ts
121121
tests/test2.test.ts
122122
```
123123

124+
Since Vitest 4.1, you may pass `--static-parse` to [parse test files](/api/advanced/vitest#parsespecifications) instead of running them to collect tests. Vitest parses test files with limited concurrency, defaulting to `os.availableParallelism()`. You can change it via the `--static-parse-concurrency` option.
125+
124126
## Shell Autocompletions
125127

126128
Vitest provides shell autocompletions for commands, options, and option values powered by [`@bomb.sh/tab`](https://github.com/bombshell-dev/tab).

packages/browser/context.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ export interface LocatorSelectors {
514514
*/
515515
getByTitle: (text: string | RegExp, options?: LocatorOptions) => Locator
516516
/**
517-
* Creates a locator capable of finding an element that matches the specified test id attribute. You can configure the attribute name with [`browser.locators.testIdAttribute`](/config/#browser-locators-testidattribute).
517+
* Creates a locator capable of finding an element that matches the specified test id attribute. You can configure the attribute name with [`browser.locators.testIdAttribute`](https://vitest.dev/config/browser/locators#browser-locators-testidattribute).
518518
* @see {@link https://vitest.dev/api/browser/locators#getbytestid}
519519
*/
520520
getByTestId: (text: string | RegExp) => Locator

packages/spy/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export interface MockInstance<T extends Procedure | Constructable = Procedure> e
224224
/**
225225
* Clears all information about every call. After calling it, all properties on `.mock` will return to their initial state. This method does not reset implementations. It is useful for cleaning up mocks between different assertions.
226226
*
227-
* To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/#clearmocks) setting in the configuration.
227+
* To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/clearmocks) setting in the configuration.
228228
* @see https://vitest.dev/api/mock#mockclear
229229
*/
230230
mockClear(): this
@@ -234,7 +234,7 @@ export interface MockInstance<T extends Procedure | Constructable = Procedure> e
234234
* Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
235235
* Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
236236
*
237-
* To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/#mockreset) setting in the configuration.
237+
* To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/mockreset) setting in the configuration.
238238
* @see https://vitest.dev/api/mock#mockreset
239239
*/
240240
mockReset(): this

packages/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"vite-plugin-pages": "^0.33.2",
8787
"vitest-browser-vue": "2.0.2",
8888
"vue": "catalog:",
89-
"vue-router": "^4.6.4",
89+
"vue-router": "^5.0.2",
9090
"vue-tsc": "^3.2.4",
9191
"vue-virtual-scroller": "2.0.0-beta.8"
9292
}

packages/vitest/src/defaults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export const configDefaults: Readonly<{
8989
}
9090
slowTestThreshold: number
9191
disableConsoleIntercept: boolean
92+
detectAsyncLeaks: boolean
9293
}> = Object.freeze({
9394
allowOnly: !isCI,
9495
isolate: true,
@@ -126,4 +127,5 @@ export const configDefaults: Readonly<{
126127
},
127128
slowTestThreshold: 300,
128129
disableConsoleIntercept: false,
130+
detectAsyncLeaks: false,
129131
})

0 commit comments

Comments
 (0)