Skip to content

Commit

Permalink
fix(vitest): show error when calling API on files that user has no ac…
Browse files Browse the repository at this point in the history
…cess to (#4085)
  • Loading branch information
sheremet-va committed Sep 8, 2023
1 parent 2fafc00 commit 8b39c11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/ui/client/components/views/ViewReport.vue
Expand Up @@ -35,7 +35,7 @@ function escapeHtml(unsafe: string) {
function createHtmlError(filter: Convert, error: ErrorWithDiff) {
let htmlError = ''
if (error.message.includes('\x1B'))
if (error.message?.includes('\x1B'))
htmlError = `<b>${error.nameStr || error.name}</b>: ${filter.toHtml(escapeHtml(error.message))}`
const startStrWithX1B = error.stackStr?.includes('\x1B')
Expand Down
7 changes: 3 additions & 4 deletions packages/vitest/src/api/setup.ts
Expand Up @@ -80,20 +80,19 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, server?: Vit
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
throw new Error(`Test file "${id}" was not registered, so it cannot be updated using the API.`)
return fs.writeFile(id, content, 'utf-8')
},
async saveSnapshotFile(id, content) {
if (!ctx.snapshot.resolvedPaths.has(id))
return
throw new Error(`Snapshot file "${id}" does not exist.`)
await fs.mkdir(dirname(id), { recursive: true })
return fs.writeFile(id, content, 'utf-8')
},
async removeSnapshotFile(id) {
if (!ctx.snapshot.resolvedPaths.has(id) || !existsSync(id))
return
throw new Error(`Snapshot file "${id}" does not exist.`)
return fs.unlink(id)
},
snapshotSaved(snapshot) {
Expand Down

0 comments on commit 8b39c11

Please sign in to comment.