[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

feat(snapshot): add option to configure snapshot directory (#4651)

authored by

Dominic Elm and committed by
GitHub
(Dec 4, 2023, 2:50 PM +0100) 20b2a857 05b0521c

+10 -4
+4 -2
packages/snapshot/src/env/node.ts
··· 1 1 import { existsSync, promises as fs } from 'node:fs' 2 2 import { basename, dirname, isAbsolute, join, resolve } from 'pathe' 3 - import type { SnapshotEnvironment } from '../types' 3 + import type { SnapshotEnvironment, SnapshotEnvironmentOptions } from '../types' 4 4 5 5 export class NodeSnapshotEnvironment implements SnapshotEnvironment { 6 + constructor(private options: SnapshotEnvironmentOptions = {}) {} 7 + 6 8 getVersion(): string { 7 9 return '1' 8 10 } ··· 21 23 return join( 22 24 join( 23 25 dirname(filepath), 24 - '__snapshots__', 26 + this.options.snapshotsDirName ?? '__snapshots__', 25 27 ), 26 28 `${basename(filepath)}.snap`, 27 29 )
+4
packages/snapshot/src/types/environment.ts
··· 7 7 readSnapshotFile(filepath: string): Promise<string | null> 8 8 removeSnapshotFile(filepath: string): Promise<void> 9 9 } 10 + 11 + export interface SnapshotEnvironmentOptions { 12 + snapshotsDirName?: string 13 + }
+2 -2
packages/snapshot/src/types/index.ts
··· 1 1 import type { OptionsReceived as PrettyFormatOptions } from 'pretty-format' 2 2 import type { RawSnapshotInfo } from '../port/rawSnapshot' 3 - import type { SnapshotEnvironment } from './environment' 3 + import type { SnapshotEnvironment, SnapshotEnvironmentOptions } from './environment' 4 4 5 - export type { SnapshotEnvironment } 5 + export type { SnapshotEnvironment, SnapshotEnvironmentOptions } 6 6 export type SnapshotData = Record<string, string> 7 7 8 8 export type SnapshotUpdateState = 'all' | 'new' | 'none'