@@ -27,15 +27,15 @@ export class VitestTestRunner implements VitestRunner {
27
27
this . snapshotClient . clear ( )
28
28
}
29
29
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 ) {
37
31
if ( this . config . logHeapUsage && typeof process !== 'undefined' )
38
32
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
+ }
39
39
}
40
40
41
41
onAfterRunTask ( test : Test ) {
@@ -63,14 +63,20 @@ export class VitestTestRunner implements VitestRunner {
63
63
}
64
64
65
65
clearModuleMocks ( this . config )
66
- await this . snapshotClient . startCurrentRun ( test . file ! . filepath , name , this . workerState . config . snapshotOptions )
67
66
68
67
this . workerState . current = test
69
68
}
70
69
71
- onBeforeRunSuite ( suite : Suite ) {
70
+ async onBeforeRunSuite ( suite : Suite ) {
72
71
if ( this . cancelRun )
73
72
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
+ }
74
80
}
75
81
76
82
onBeforeTryTask ( test : Test ) {
0 commit comments