diff --git a/packages/vitest/src/api/setup.ts b/packages/vitest/src/api/setup.ts index 0215d1e70f806..795958b77766f 100644 --- a/packages/vitest/src/api/setup.ts +++ b/packages/vitest/src/api/setup.ts @@ -70,7 +70,7 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, server?: Vit return ctx.snapshot.resolveRawPath(testPath, rawPath) }, async readSnapshotFile(snapshotPath) { - if (!ctx.snapshot.resolvedPaths.has(snapshotPath) || !existsSync(snapshotPath)) + if (!ctx.snapshot.resolvedPaths.has(snapshotPath)) return null return fs.readFile(snapshotPath, 'utf-8') }, @@ -80,13 +80,13 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, server?: Vit return fs.readFile(id, 'utf-8') }, async saveSnapshotFile(id, content) { - if (!ctx.state.filesMap.has(id)) + if (!ctx.snapshot.resolvedPaths.has(id)) return await fs.mkdir(dirname(id), { recursive: true }) return fs.writeFile(id, content, 'utf-8') }, async removeSnapshotFile(id) { - if (!ctx.state.filesMap.has(id) || !existsSync(id)) + if (!ctx.snapshot.resolvedPaths.has(id)) return return fs.unlink(id) },