Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snapshot): toMatchFileSnapshot ensure dir exists #3155

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/browser/src/client/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class BrowserSnapshotEnvironment implements SnapshotEnvironment {
return rpc().removeFile(filepath)
}

async prepareDirectory(filepath: string): Promise<void> {
await rpc().createDirectory(filepath)
async prepareDirectory(dirPath: string): Promise<void> {
await rpc().createDirectory(dirPath)
}
}
5 changes: 3 additions & 2 deletions packages/snapshot/src/env/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export class NodeSnapshotEnvironment implements SnapshotEnvironment {
)
}

async prepareDirectory(filepath: string): Promise<void> {
await fs.mkdir(filepath, { recursive: true })
async prepareDirectory(dirPath: string): Promise<void> {
await fs.mkdir(dirPath, { recursive: true })
}

async saveSnapshotFile(filepath: string, snapshot: string): Promise<void> {
await fs.mkdir(dirname(filepath), { recursive: true })
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
await fs.writeFile(filepath, snapshot, 'utf-8')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/snapshot/src/types/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface SnapshotEnvironment {
getHeader(): string
resolvePath(filepath: string): Promise<string>
resolveRawPath(testPath: string, rawPath: string): Promise<string>
prepareDirectory(filepath: string): Promise<void>
prepareDirectory(dirPath: string): Promise<void>
saveSnapshotFile(filepath: string, snapshot: string): Promise<void>
readSnapshotFile(filepath: string): Promise<string | null>
removeSnapshotFile(filepath: string): Promise<void>
Expand Down