@@ -27,15 +27,15 @@ export class VitestTestRunner implements VitestRunner {
2727 this . snapshotClient . clear ( )
2828 }
2929
30- async onAfterRunFiles ( ) {
31- const result = await this . snapshotClient . finishCurrentRun ( )
32- if ( result )
33- await rpc ( ) . snapshotSaved ( result )
34- }
35-
36- onAfterRunSuite ( suite : Suite ) {
30+ async onAfterRunSuite ( suite : Suite ) {
3731 if ( this . config . logHeapUsage && typeof process !== 'undefined' )
3832 suite . result ! . heap = process . memoryUsage ( ) . heapUsed
33+
34+ if ( suite . mode !== 'skip' && typeof suite . filepath !== 'undefined' ) {
35+ const result = await this . snapshotClient . finishCurrentRun ( )
36+ if ( result )
37+ await rpc ( ) . snapshotSaved ( result )
38+ }
3939 }
4040
4141 onAfterRunTask ( test : Test ) {
@@ -63,14 +63,20 @@ export class VitestTestRunner implements VitestRunner {
6363 }
6464
6565 clearModuleMocks ( this . config )
66- await this . snapshotClient . startCurrentRun ( test . file ! . filepath , name , this . workerState . config . snapshotOptions )
6766
6867 this . workerState . current = test
6968 }
7069
71- onBeforeRunSuite ( suite : Suite ) {
70+ async onBeforeRunSuite ( suite : Suite ) {
7271 if ( this . cancelRun )
7372 suite . mode = 'skip'
73+
74+ // initialize snapshot state before running file suite
75+ if ( suite . mode !== 'skip' && typeof suite . filepath !== 'undefined' ) {
76+ // default "name" is irrelevant for Vitest since each snapshot assertion
77+ // (e.g. `toMatchSnapshot`) specifies "filepath" / "name" pair explicitly
78+ await this . snapshotClient . startCurrentRun ( suite . filepath , '__default_name_' , this . workerState . config . snapshotOptions )
79+ }
7480 }
7581
7682 onBeforeTryTask ( test : Test ) {
0 commit comments