Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore "plugins" field in snapshotFormat option #4204

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,12 @@ Will call [`vi.unstubAllGlobals`](/api/vi#vi-unstuballglobals) before each test.

Format options for snapshot testing. These options are passed down to [`pretty-format`](https://www.npmjs.com/package/pretty-format).

::: tip
Beware that `plugins` field on this object will be ignored.

If you need to extend snapshot serializer via pretty-format plugins, please, use [`expect.addSnapshotSerializer`](/api/expect#expect-addsnapshotserializer) API.
:::

### resolveSnapshotPath<NonProjectOption />

- **Type**: `(testPath: string, snapExtension: string) => string`
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ export function resolveConfig(
: new RegExp(resolved.testNamePattern)
: undefined

if (resolved.snapshotFormat && 'plugins' in resolved.snapshotFormat)
(resolved.snapshotFormat as any).plugins = []

const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT
resolved.snapshotOptions = {
snapshotFormat: resolved.snapshotFormat || {},
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export interface InlineConfig {
/**
* Format options for snapshot testing.
*/
snapshotFormat?: PrettyFormatOptions
snapshotFormat?: Omit<PrettyFormatOptions, 'plugins'>

/**
* Path to a module which has a default export of diff config.
Expand Down
Loading