diff --git a/docs/config/resolvesnapshotpath.md b/docs/config/resolvesnapshotpath.md index 981ff41264c0..c63abfd558d5 100644 --- a/docs/config/resolvesnapshotpath.md +++ b/docs/config/resolvesnapshotpath.md @@ -19,3 +19,23 @@ export default defineConfig({ }, }) ``` + +You can also use the `context` parameter to access the project's serialized config. This is useful when you have multiple [projects](/guide/projects) and want to store snapshots in different locations based on the project name: + +```ts +import { basename, dirname, join } from 'node:path' +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + resolveSnapshotPath(testPath, snapExtension, context) { + return join( + dirname(testPath), + '__snapshots__', + context.config.name ?? 'default', + basename(testPath) + snapExtension, + ) + }, + }, +}) +```