Skip to content

Commit

Permalink
fix: ignore "plugins" field in snapshotFormat option (#4204)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 1, 2023
1 parent fc947ce commit db1ff43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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

0 comments on commit db1ff43

Please sign in to comment.