@@ -69,25 +69,36 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, server?: Vit
6969 resolveSnapshotRawPath ( testPath , rawPath ) {
7070 return ctx . snapshot . resolveRawPath ( testPath , rawPath )
7171 } ,
72- removeFile ( id ) {
73- return fs . unlink ( id )
74- } ,
75- createDirectory ( id ) {
76- return fs . mkdir ( id , { recursive : true } )
72+ async readSnapshotFile ( snapshotPath ) {
73+ if ( ! ctx . snapshot . resolvedPaths . has ( snapshotPath ) || ! existsSync ( snapshotPath ) )
74+ return null
75+ return fs . readFile ( snapshotPath , 'utf-8' )
7776 } ,
78- async readFile ( id ) {
79- if ( ! existsSync ( id ) )
77+ async readTestFile ( id ) {
78+ if ( ! ctx . state . filesMap . has ( id ) || ! existsSync ( id ) )
8079 return null
8180 return fs . readFile ( id , 'utf-8' )
8281 } ,
82+ async saveTestFile ( id , content ) {
83+ // can save only already existing test file
84+ if ( ! ctx . state . filesMap . has ( id ) || ! existsSync ( id ) )
85+ return
86+ return fs . writeFile ( id , content , 'utf-8' )
87+ } ,
88+ async saveSnapshotFile ( id , content ) {
89+ if ( ! ctx . snapshot . resolvedPaths . has ( id ) )
90+ return
91+ await fs . mkdir ( dirname ( id ) , { recursive : true } )
92+ return fs . writeFile ( id , content , 'utf-8' )
93+ } ,
94+ async removeSnapshotFile ( id ) {
95+ if ( ! ctx . snapshot . resolvedPaths . has ( id ) || ! existsSync ( id ) )
96+ return
97+ return fs . unlink ( id )
98+ } ,
8399 snapshotSaved ( snapshot ) {
84100 ctx . snapshot . add ( snapshot )
85101 } ,
86- async writeFile ( id , content , ensureDir ) {
87- if ( ensureDir )
88- await fs . mkdir ( dirname ( id ) , { recursive : true } )
89- return await fs . writeFile ( id , content , 'utf-8' )
90- } ,
91102 async rerun ( files ) {
92103 await ctx . rerunFiles ( files )
93104 } ,
0 commit comments