From db1ff438075d34389de5bb4f5cd08370a08337d5 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 79acb8fce98d..3d2d26969c45 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 c124d62ff682..6ec90519156c 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 434e0542e873..abb5c665320b 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.