Skip to content

Commit

Permalink
Merge branch 'main' into feat/change-default-to-stack
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored May 6, 2024
2 parents 0f29403 + 2a80e95 commit dcdcbbe
Show file tree
Hide file tree
Showing 795 changed files with 10,839 additions and 26,257 deletions.
33 changes: 7 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ jobs:
- name: Lint
run: pnpm run lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/setup-and-cache

- name: Install
run: pnpm i

- name: Build
run: pnpm run build

- name: Typecheck
run: pnpm run typecheck

test:
runs-on: ${{ matrix.os }}

Expand All @@ -56,7 +40,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node_version: [18, 20]
node_version: [18, 20, 22]
include:
- os: macos-14
node_version: 20
Expand Down Expand Up @@ -85,11 +69,8 @@ jobs:
- name: Test
run: pnpm run test:ci

- name: Test No Threads
run: pnpm run test:ci:no-threads

- name: Test Vm Threads
run: pnpm run test:ci:vm-threads
- name: Test Examples
run: pnpm run test:examples

test-ui:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -147,8 +128,6 @@ jobs:

timeout-minutes: 30

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

Expand All @@ -170,6 +149,8 @@ jobs:

- name: Test Browser (webdriverio)
run: pnpm run test:browser:webdriverio
env:
BROWSER: ${{ matrix.browser[0] }}

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

timeout-minutes: 30

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

Expand All @@ -208,6 +187,8 @@ jobs:

- name: Test Browser (webdriverio)
run: pnpm run test:browser:webdriverio
env:
BROWSER: ${{ matrix.browser[0] }}

- name: Test Browser (playwright)
run: pnpm run test:browser:playwright
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ docs/public/user-avatars
docs/public/sponsors
.eslintcache
docs/.vitepress/cache/
!test/cwd/**/.cache
!test/cli/fixtures/dotted-files/**/.cache
113 changes: 112 additions & 1 deletion docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,46 @@ By providing an object instead of a string you can define individual outputs whe

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

#### benchmark.outputJson <Version>1.6.0</Version> {#benchmark-outputJson}

- **Type:** `string | undefined`
- **Default:** `undefined`

A file path to store the benchmark result, which can be used for `--compare` option later.

For example:

```sh
# save main branch's result
git checkout main
vitest bench --outputJson main.json

# change a branch and compare against main
git checkout feature
vitest bench --compare main.json
```

#### benchmark.compare <Version>1.6.0</Version> {#benchmark-compare}

- **Type:** `string | undefined`
- **Default:** `undefined`

A file path to a previous benchmark result to compare against current runs.

### alias

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

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

::: warning
Vitest uses Vite SSR primitives to run tests which has [certain pitfalls](https://vitejs.dev/guide/ssr.html#ssr-externals).

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).
2. Vitest does not support aliasing `require` calls.
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.
:::

### globals

- **Type:** `boolean`
Expand Down Expand Up @@ -1094,7 +1128,7 @@ List of files included in coverage as glob patterns
'cypress/**',
'test?(s)/**',
'test?(-*).?(c|m)[jt]s?(x)',
'**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
'**/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
'**/vitest.{workspace,projects}.[jt]s?(on)',
Expand Down Expand Up @@ -1604,6 +1638,55 @@ This option has no effect on tests running inside Node.js.
If you rely on spying on ES modules with `vi.spyOn`, you can enable this experimental feature to allow spying on module exports.
#### browser.indexScripts <Version>1.6.0</Version> {#browser-indexscripts}
- **Type:** `BrowserScript[]`
- **Default:** `[]`
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.
The script `src` and `content` will be processed by Vite plugins. Script should be provided in the following shape:
```ts
export interface BrowserScript {
/**
* If "content" is provided and type is "module", this will be its identifier.
*
* If you are using TypeScript, you can add `.ts` extension here for example.
* @default `injected-${index}.js`
*/
id?: string
/**
* JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
*
* You can use `id` to give Vite a hint about the file extension.
*/
content?: string
/**
* Path to the script. This value is resolved by Vite so it can be a node module or a file path.
*/
src?: string
/**
* If the script should be loaded asynchronously.
*/
async?: boolean
/**
* Script type.
* @default 'module'
*/
type?: string
}
```
#### browser.testerScripts <Version>1.6.0</Version> {#browser-testerscripts}
- **Type:** `BrowserScript[]`
- **Default:** `[]`
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.
The script `src` and `content` will be processed by Vite plugins.
### clearMocks
- **Type:** `boolean`
Expand Down Expand Up @@ -2192,3 +2275,31 @@ The `location` property has `column` and `line` values that correspond to the `t
::: tip
This option has no effect if you do not use custom code that relies on this.
:::
### snapshotEnvironment <Version>1.6.0</Version> {#snapshotEnvironment}
- **Type:** `string`
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.
This object should have the shape of `SnapshotEnvironment` and is used to resolve and read/write snapshot files:
```ts
export interface SnapshotEnvironment {
getVersion: () => string
getHeader: () => string
resolvePath: (filepath: string) => Promise<string>
resolveRawPath: (testPath: string, rawPath: string) => Promise<string>
saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>
readSnapshotFile: (filepath: string) => Promise<string | null>
removeSnapshotFile: (filepath: string) => Promise<void>
}
```
You can extend default `VitestSnapshotEnvironment` from `vitest/snapshot` entry point if you need to overwrite only a part of the API.
::: warning
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.
If you just need to configure snapshots feature, use [`snapshotFormat`](#snapshotformat) or [`resolveSnapshotPath`](#resolvesnapshotpath) options.
:::
7 changes: 4 additions & 3 deletions docs/guide/cli-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
| `--coverage.cleanOnRerun` | Clean coverage report on watch rerun (default: true) |
| `--coverage.reportsDirectory <path>` | Directory to write coverage report to (default: ./coverage) |
| `--coverage.reporter <name>` | Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config/#coverage-reporter) for more information (default: `["text", "html", "clover", "json"]`) |
| `--coverage.reportOnFailure` | Generate coverage report even when tests fail (default: false) |
| `--coverage.allowExternal` | Collect coverage of files outside the project root (default: false) |
| `--coverage.skipFull` | Do not show files with 100% statement, branch, and function coverage (default: false) |
| `--coverage.reportOnFailure` | Generate coverage report even when tests fail (default: `false`) |
| `--coverage.allowExternal` | Collect coverage of files outside the project root (default: `false`) |
| `--coverage.skipFull` | Do not show files with 100% statement, branch, and function coverage (default: `false`) |
| `--coverage.thresholds.100` | Shortcut to set all coverage thresholds to 100 (default: `false`) |
| `--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`) |
| `--coverage.thresholds.autoUpdate` | Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: `false`) |
Expand Down Expand Up @@ -119,3 +119,4 @@
| `--segfaultRetry <times>` | Retry the test suite if it crashes due to a segfault (default: `true`) |
| `--no-color` | Removes colors from the console output |
| `--clearScreen` | Clear terminal screen when re-running tests during watch mode (default: `true`) |
| `--standalone` | Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`) |
3 changes: 3 additions & 0 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ describe('sort', () => {
})
```

<img alt="Benchmark report" img-dark src="https://github.com/vitest-dev/vitest/assets/4232207/6f0383ea-38ba-4f14-8a05-ab243afea01d">
<img alt="Benchmark report" img-light src="https://github.com/vitest-dev/vitest/assets/4232207/efbcb427-ecf1-4882-88de-210cd73415f6">

## Type Testing <Badge type="warning">Experimental</Badge> {#type-testing}

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.
Expand Down
8 changes: 8 additions & 0 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ const { cloneDeep } = jest.requireActual('lodash/cloneDeep') // [!code --]
const { cloneDeep } = await vi.importActual('lodash/cloneDeep') // [!code ++]
```

### Extends mocking to external libraries

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).

```
server.deps.inline: ["lib-name"]
```

### Accessing the Return Values of a Mocked Promise

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.
Expand Down
Loading

0 comments on commit dcdcbbe

Please sign in to comment.