/
snapshot.ts
36 lines (28 loc) · 993 Bytes
/
snapshot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { rpc } from './rpc'
import type { SnapshotEnvironment } from '#types'
export class BrowserSnapshotEnvironment implements SnapshotEnvironment {
getVersion(): string {
return '1'
}
getHeader(): string {
return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`
}
readSnapshotFile(filepath: string): Promise<string | null> {
return rpc().readFile(filepath)
}
saveSnapshotFile(filepath: string, snapshot: string): Promise<void> {
return rpc().writeFile(filepath, snapshot)
}
resolvePath(filepath: string): Promise<string> {
return rpc().resolveSnapshotPath(filepath)
}
resolveRawPath(testPath: string, rawPath: string): Promise<string> {
return rpc().resolveSnapshotRawPath(testPath, rawPath)
}
removeSnapshotFile(filepath: string): Promise<void> {
return rpc().removeFile(filepath)
}
async prepareDirectory(filepath: string): Promise<void> {
await rpc().createDirectory(filepath)
}
}