Skip to content

Commit

Permalink
fix: allow saving test files in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 15, 2023
1 parent d729128 commit 7ff15fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ui/client/components/views/ViewEditor.vue
Expand Up @@ -116,7 +116,7 @@ watch([cm, failed], ([cmValue]) => {
async function onSave(content: string) {
hasBeenEdited.value = true
await client.rpc.writeFile(props.file!.filepath, content)
await client.rpc.saveTestFile(props.file!.filepath, content)
serverCode.value = content
draft.value = false
}
Expand Down
6 changes: 6 additions & 0 deletions packages/vitest/src/api/setup.ts
Expand Up @@ -79,6 +79,12 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, server?: Vit
return null
return fs.readFile(id, 'utf-8')
},
async saveTestFile(id, content) {
// can save only already existing test file
if (!ctx.state.filesMap.has(id) || !existsSync(id))
return
return fs.writeFile(id, content, 'utf-8')
},
async saveSnapshotFile(id, content) {
if (!ctx.snapshot.resolvedPaths.has(id))
return
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/api/types.ts
Expand Up @@ -23,6 +23,7 @@ export interface WebSocketHandlers {
getTransformResult(id: string): Promise<TransformResultWithSource | undefined>
readSnapshotFile(id: string): Promise<string | null>
readTestFile(id: string): Promise<string | null>
saveTestFile(id: string, content: string): Promise<void>
saveSnapshotFile(id: string, content: string): Promise<void>
removeSnapshotFile(id: string): Promise<void>
snapshotSaved(snapshot: SnapshotResult): void
Expand Down

0 comments on commit 7ff15fb

Please sign in to comment.