Skip to content

Commit

Permalink
feat(snapshot): add option to configure snapshot directory (#4651)
Browse files Browse the repository at this point in the history
  • Loading branch information
d3lm committed Dec 4, 2023
1 parent 05b0521 commit 20b2a85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/snapshot/src/env/node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { existsSync, promises as fs } from 'node:fs'
import { basename, dirname, isAbsolute, join, resolve } from 'pathe'
import type { SnapshotEnvironment } from '../types'
import type { SnapshotEnvironment, SnapshotEnvironmentOptions } from '../types'

export class NodeSnapshotEnvironment implements SnapshotEnvironment {
constructor(private options: SnapshotEnvironmentOptions = {}) {}

getVersion(): string {
return '1'
}
Expand All @@ -21,7 +23,7 @@ export class NodeSnapshotEnvironment implements SnapshotEnvironment {
return join(
join(
dirname(filepath),
'__snapshots__',
this.options.snapshotsDirName ?? '__snapshots__',
),
`${basename(filepath)}.snap`,
)
Expand Down
4 changes: 4 additions & 0 deletions packages/snapshot/src/types/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export interface SnapshotEnvironment {
readSnapshotFile(filepath: string): Promise<string | null>
removeSnapshotFile(filepath: string): Promise<void>
}

export interface SnapshotEnvironmentOptions {
snapshotsDirName?: string
}
4 changes: 2 additions & 2 deletions packages/snapshot/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OptionsReceived as PrettyFormatOptions } from 'pretty-format'
import type { RawSnapshotInfo } from '../port/rawSnapshot'
import type { SnapshotEnvironment } from './environment'
import type { SnapshotEnvironment, SnapshotEnvironmentOptions } from './environment'

export type { SnapshotEnvironment }
export type { SnapshotEnvironment, SnapshotEnvironmentOptions }
export type SnapshotData = Record<string, string>

export type SnapshotUpdateState = 'all' | 'new' | 'none'
Expand Down

0 comments on commit 20b2a85

Please sign in to comment.