Skip to content

Commit db1ff43

Browse files
authored
fix: ignore "plugins" field in snapshotFormat option (#4204)
1 parent fc947ce commit db1ff43

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

docs/config/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,12 @@ Will call [`vi.unstubAllGlobals`](/api/vi#vi-unstuballglobals) before each test.
13201320

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

1323+
::: tip
1324+
Beware that `plugins` field on this object will be ignored.
1325+
1326+
If you need to extend snapshot serializer via pretty-format plugins, please, use [`expect.addSnapshotSerializer`](/api/expect#expect-addsnapshotserializer) API.
1327+
:::
1328+
13231329
### resolveSnapshotPath<NonProjectOption />
13241330

13251331
- **Type**: `(testPath: string, snapExtension: string) => string`

packages/vitest/src/node/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ export function resolveConfig(
214214
: new RegExp(resolved.testNamePattern)
215215
: undefined
216216

217+
if (resolved.snapshotFormat && 'plugins' in resolved.snapshotFormat)
218+
(resolved.snapshotFormat as any).plugins = []
219+
217220
const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT
218221
resolved.snapshotOptions = {
219222
snapshotFormat: resolved.snapshotFormat || {},

packages/vitest/src/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ export interface InlineConfig {
537537
/**
538538
* Format options for snapshot testing.
539539
*/
540-
snapshotFormat?: PrettyFormatOptions
540+
snapshotFormat?: Omit<PrettyFormatOptions, 'plugins'>
541541

542542
/**
543543
* Path to a module which has a default export of diff config.

0 commit comments

Comments
 (0)