Skip to content

Commit dcdcbbe

Browse files
authored
Merge branch 'main' into feat/change-default-to-stack
2 parents 0f29403 + 2a80e95 commit dcdcbbe

795 files changed

Lines changed: 10839 additions & 26257 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: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ jobs:
3232
- name: Lint
3333
run: pnpm run lint
3434

35-
typecheck:
36-
runs-on: ubuntu-latest
37-
steps:
38-
- uses: actions/checkout@v4
39-
40-
- uses: ./.github/actions/setup-and-cache
41-
42-
- name: Install
43-
run: pnpm i
44-
45-
- name: Build
46-
run: pnpm run build
47-
48-
- name: Typecheck
49-
run: pnpm run typecheck
50-
5135
test:
5236
runs-on: ${{ matrix.os }}
5337

@@ -56,7 +40,7 @@ jobs:
5640
strategy:
5741
matrix:
5842
os: [ubuntu-latest]
59-
node_version: [18, 20]
43+
node_version: [18, 20, 22]
6044
include:
6145
- os: macos-14
6246
node_version: 20
@@ -85,11 +69,8 @@ jobs:
8569
- name: Test
8670
run: pnpm run test:ci
8771

88-
- name: Test No Threads
89-
run: pnpm run test:ci:no-threads
90-
91-
- name: Test Vm Threads
92-
run: pnpm run test:ci:vm-threads
72+
- name: Test Examples
73+
run: pnpm run test:examples
9374

9475
test-ui:
9576
runs-on: ubuntu-latest
@@ -147,8 +128,6 @@ jobs:
147128

148129
timeout-minutes: 30
149130

150-
env:
151-
BROWSER: ${{ matrix.browser[0] }}
152131
steps:
153132
- uses: actions/checkout@v4
154133

@@ -170,6 +149,8 @@ jobs:
170149

171150
- name: Test Browser (webdriverio)
172151
run: pnpm run test:browser:webdriverio
152+
env:
153+
BROWSER: ${{ matrix.browser[0] }}
173154

174155
- name: Test Browser (playwright)
175156
run: pnpm run test:browser:playwright
@@ -185,8 +166,6 @@ jobs:
185166

186167
timeout-minutes: 30
187168

188-
env:
189-
BROWSER: ${{ matrix.browser[0] }}
190169
steps:
191170
- uses: actions/checkout@v4
192171

@@ -208,6 +187,8 @@ jobs:
208187

209188
- name: Test Browser (webdriverio)
210189
run: pnpm run test:browser:webdriverio
190+
env:
191+
BROWSER: ${{ matrix.browser[0] }}
211192

212193
- name: Test Browser (playwright)
213194
run: pnpm run test:browser:playwright

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ docs/public/user-avatars
2727
docs/public/sponsors
2828
.eslintcache
2929
docs/.vitepress/cache/
30-
!test/cwd/**/.cache
30+
!test/cli/fixtures/dotted-files/**/.cache

docs/config/index.md

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,46 @@ By providing an object instead of a string you can define individual outputs whe
312312

313313
To provide object via CLI command, use the following syntax: `--outputFile.json=./path --outputFile.junit=./other-path`.
314314

315+
#### benchmark.outputJson <Version>1.6.0</Version> {#benchmark-outputJson}
316+
317+
- **Type:** `string | undefined`
318+
- **Default:** `undefined`
319+
320+
A file path to store the benchmark result, which can be used for `--compare` option later.
321+
322+
For example:
323+
324+
```sh
325+
# save main branch's result
326+
git checkout main
327+
vitest bench --outputJson main.json
328+
329+
# change a branch and compare against main
330+
git checkout feature
331+
vitest bench --compare main.json
332+
```
333+
334+
#### benchmark.compare <Version>1.6.0</Version> {#benchmark-compare}
335+
336+
- **Type:** `string | undefined`
337+
- **Default:** `undefined`
338+
339+
A file path to a previous benchmark result to compare against current runs.
340+
315341
### alias
316342

317343
- **Type:** `Record<string, string> | Array<{ find: string | RegExp, replacement: string, customResolver?: ResolverFunction | ResolverObject }>`
318344

319345
Define custom aliases when running inside tests. They will be merged with aliases from `resolve.alias`.
320346

347+
::: warning
348+
Vitest uses Vite SSR primitives to run tests which has [certain pitfalls](https://vitejs.dev/guide/ssr.html#ssr-externals).
349+
350+
1. Aliases affect only modules imported directly with an `import` keyword by an [inlined](#server-deps-inline) module (all source code is inlined by default).
351+
2. Vitest does not support aliasing `require` calls.
352+
3. If you are aliasing an external dependency (e.g., `react` -> `preact`), you may want to alias the actual `node_modules` packages instead to make it work for externalized dependencies. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.io/aliases/) support aliasing via the `npm:` prefix.
353+
:::
354+
321355
### globals
322356

323357
- **Type:** `boolean`
@@ -1094,7 +1128,7 @@ List of files included in coverage as glob patterns
10941128
'cypress/**',
10951129
'test?(s)/**',
10961130
'test?(-*).?(c|m)[jt]s?(x)',
1097-
'**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
1131+
'**/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)',
10981132
'**/__tests__/**',
10991133
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
11001134
'**/vitest.{workspace,projects}.[jt]s?(on)',
@@ -1604,6 +1638,55 @@ This option has no effect on tests running inside Node.js.
16041638

16051639
If you rely on spying on ES modules with `vi.spyOn`, you can enable this experimental feature to allow spying on module exports.
16061640

1641+
#### browser.indexScripts <Version>1.6.0</Version> {#browser-indexscripts}
1642+
1643+
- **Type:** `BrowserScript[]`
1644+
- **Default:** `[]`
1645+
1646+
Custom scripts that should be injected into the index HTML before test iframes are initiated. This HTML document only sets up iframes and doesn't actually import your code.
1647+
1648+
The script `src` and `content` will be processed by Vite plugins. Script should be provided in the following shape:
1649+
1650+
```ts
1651+
export interface BrowserScript {
1652+
/**
1653+
* If "content" is provided and type is "module", this will be its identifier.
1654+
*
1655+
* If you are using TypeScript, you can add `.ts` extension here for example.
1656+
* @default `injected-${index}.js`
1657+
*/
1658+
id?: string
1659+
/**
1660+
* JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
1661+
*
1662+
* You can use `id` to give Vite a hint about the file extension.
1663+
*/
1664+
content?: string
1665+
/**
1666+
* Path to the script. This value is resolved by Vite so it can be a node module or a file path.
1667+
*/
1668+
src?: string
1669+
/**
1670+
* If the script should be loaded asynchronously.
1671+
*/
1672+
async?: boolean
1673+
/**
1674+
* Script type.
1675+
* @default 'module'
1676+
*/
1677+
type?: string
1678+
}
1679+
```
1680+
1681+
#### browser.testerScripts <Version>1.6.0</Version> {#browser-testerscripts}
1682+
1683+
- **Type:** `BrowserScript[]`
1684+
- **Default:** `[]`
1685+
1686+
Custom scripts that should be injected into the tester HTML before the tests environment is initiated. This is useful to inject polyfills required for Vitest browser implementation. It is recommended to use [`setupFiles`](#setupfiles) in almost all cases instead of this.
1687+
1688+
The script `src` and `content` will be processed by Vite plugins.
1689+
16071690
### clearMocks
16081691

16091692
- **Type:** `boolean`
@@ -2192,3 +2275,31 @@ The `location` property has `column` and `line` values that correspond to the `t
21922275
::: tip
21932276
This option has no effect if you do not use custom code that relies on this.
21942277
:::
2278+
2279+
### snapshotEnvironment <Version>1.6.0</Version> {#snapshotEnvironment}
2280+
2281+
- **Type:** `string`
2282+
2283+
Path to a custom snapshot environment implementation. This is useful if you are running your tests in an environment that doesn't support Node.js APIs. This option doesn't have any effect on a browser runner.
2284+
2285+
This object should have the shape of `SnapshotEnvironment` and is used to resolve and read/write snapshot files:
2286+
2287+
```ts
2288+
export interface SnapshotEnvironment {
2289+
getVersion: () => string
2290+
getHeader: () => string
2291+
resolvePath: (filepath: string) => Promise<string>
2292+
resolveRawPath: (testPath: string, rawPath: string) => Promise<string>
2293+
saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>
2294+
readSnapshotFile: (filepath: string) => Promise<string | null>
2295+
removeSnapshotFile: (filepath: string) => Promise<void>
2296+
}
2297+
```
2298+
2299+
You can extend default `VitestSnapshotEnvironment` from `vitest/snapshot` entry point if you need to overwrite only a part of the API.
2300+
2301+
::: warning
2302+
This is a low-level option and should be used only for advanced cases where you don't have access to default Node.js APIs.
2303+
2304+
If you just need to configure snapshots feature, use [`snapshotFormat`](#snapshotformat) or [`resolveSnapshotPath`](#resolvesnapshotpath) options.
2305+
:::

docs/guide/cli-table.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
| `--coverage.cleanOnRerun` | Clean coverage report on watch rerun (default: true) |
2626
| `--coverage.reportsDirectory <path>` | Directory to write coverage report to (default: ./coverage) |
2727
| `--coverage.reporter <name>` | Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config/#coverage-reporter) for more information (default: `["text", "html", "clover", "json"]`) |
28-
| `--coverage.reportOnFailure` | Generate coverage report even when tests fail (default: false) |
29-
| `--coverage.allowExternal` | Collect coverage of files outside the project root (default: false) |
30-
| `--coverage.skipFull` | Do not show files with 100% statement, branch, and function coverage (default: false) |
28+
| `--coverage.reportOnFailure` | Generate coverage report even when tests fail (default: `false`) |
29+
| `--coverage.allowExternal` | Collect coverage of files outside the project root (default: `false`) |
30+
| `--coverage.skipFull` | Do not show files with 100% statement, branch, and function coverage (default: `false`) |
3131
| `--coverage.thresholds.100` | Shortcut to set all coverage thresholds to 100 (default: `false`) |
3232
| `--coverage.thresholds.perFile` | Check thresholds per file. See `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches` and `--coverage.thresholds.statements` for the actual thresholds (default: `false`) |
3333
| `--coverage.thresholds.autoUpdate` | Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: `false`) |
@@ -119,3 +119,4 @@
119119
| `--segfaultRetry <times>` | Retry the test suite if it crashes due to a segfault (default: `true`) |
120120
| `--no-color` | Removes colors from the console output |
121121
| `--clearScreen` | Clear terminal screen when re-running tests during watch mode (default: `true`) |
122+
| `--standalone` | Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`) |

docs/guide/features.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ describe('sort', () => {
210210
})
211211
```
212212

213+
<img alt="Benchmark report" img-dark src="https://github.com/vitest-dev/vitest/assets/4232207/6f0383ea-38ba-4f14-8a05-ab243afea01d">
214+
<img alt="Benchmark report" img-light src="https://github.com/vitest-dev/vitest/assets/4232207/efbcb427-ecf1-4882-88de-210cd73415f6">
215+
213216
## Type Testing <Badge type="warning">Experimental</Badge> {#type-testing}
214217

215218
Since Vitest 0.25.0 you can [write tests](/guide/testing-types) to catch type regressions. Vitest comes with [`expect-type`](https://github.com/mmkal/expect-type) package to provide you with a similar and easy to understand API.

docs/guide/migration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ const { cloneDeep } = jest.requireActual('lodash/cloneDeep') // [!code --]
194194
const { cloneDeep } = await vi.importActual('lodash/cloneDeep') // [!code ++]
195195
```
196196

197+
### Extends mocking to external libraries
198+
199+
Where Jest does it by default, when mocking a module and wanting this mocking to be extended to other external libraries that use the same module, you should explicitly tell which 3rd-party library you want to be mocked, so the external library would be part of your source code, by using [server.deps.inline](https://vitest.dev/config/#server-deps-inline).
200+
201+
```
202+
server.deps.inline: ["lib-name"]
203+
```
204+
197205
### Accessing the Return Values of a Mocked Promise
198206

199207
Both Jest and Vitest store the results of all mock calls in the [`mock.results`](/api/mock.html#mock-results) array, where the return values of each call are stored in the `value` property.

0 commit comments

Comments
 (0)