From 702067f0f98d82750b64e9831b8473bae0c9532b Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 1 Oct 2023 14:46:37 +0200 Subject: [PATCH] fix: ignore "plugins" field in snapshotFormat option (#4204) --- docs/config/index.md | 6 ++++++ packages/vitest/src/node/config.ts | 3 +++ packages/vitest/src/types/config.ts | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 79acb8fce98d9..3d2d26969c452 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -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 - **Type**: `(testPath: string, snapExtension: string) => string` diff --git a/packages/vitest/src/node/config.ts b/packages/vitest/src/node/config.ts index c124d62ff6822..6ec90519156c5 100644 --- a/packages/vitest/src/node/config.ts +++ b/packages/vitest/src/node/config.ts @@ -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 || {}, diff --git a/packages/vitest/src/types/config.ts b/packages/vitest/src/types/config.ts index 434e0542e8738..abb5c665320b3 100644 --- a/packages/vitest/src/types/config.ts +++ b/packages/vitest/src/types/config.ts @@ -537,7 +537,7 @@ export interface InlineConfig { /** * Format options for snapshot testing. */ - snapshotFormat?: PrettyFormatOptions + snapshotFormat?: Omit /** * Path to a module which has a default export of diff config.