@@ -29,6 +29,8 @@ class Runner extends Emittery {
2929
3030 this . activeRunnables = new Set ( ) ;
3131 this . boundCompareTestSnapshot = this . compareTestSnapshot . bind ( this ) ;
32+ this . skippedSnapshots = false ;
33+ this . boundSkipSnapshot = this . skipSnapshot . bind ( this ) ;
3234 this . interrupted = false ;
3335 this . snapshots = null ;
3436 this . nextTaskIndex = 0 ;
@@ -199,8 +201,19 @@ class Runner extends Emittery {
199201 return this . snapshots . compare ( options ) ;
200202 }
201203
204+ skipSnapshot ( ) {
205+ this . skippedSnapshots = true ;
206+ }
207+
202208 saveSnapshotState ( ) {
203- if ( this . updateSnapshots && ( this . runOnlyExclusive || this . skippingTests ) ) {
209+ if (
210+ this . updateSnapshots &&
211+ (
212+ this . runOnlyExclusive ||
213+ this . skippingTests ||
214+ this . skippedSnapshots
215+ )
216+ ) {
204217 return { cannotSave : true } ;
205218 }
206219
@@ -209,9 +222,11 @@ class Runner extends Emittery {
209222 }
210223
211224 if ( this . updateSnapshots ) {
212- // TODO: There may be unused snapshot files if no test caused the
213- // snapshots to be loaded. Prune them. But not if tests (including hooks!)
214- // were skipped. Perhaps emit a warning if this occurs?
225+ return { touchedFiles : snapshotManager . cleanSnapshots ( {
226+ file : this . file ,
227+ fixedLocation : this . snapshotDir ,
228+ projectDir : this . projectDir
229+ } ) } ;
215230 }
216231
217232 return { } ;
@@ -297,6 +312,7 @@ class Runner extends Emittery {
297312 task . implementation :
298313 t => task . implementation . apply ( null , [ t ] . concat ( task . args ) ) ,
299314 compareTestSnapshot : this . boundCompareTestSnapshot ,
315+ skipSnapshot : this . boundSkipSnapshot ,
300316 updateSnapshots : this . updateSnapshots ,
301317 metadata : { ...task . metadata , associatedTaskIndex} ,
302318 powerAssert : this . powerAssert ,
@@ -349,6 +365,7 @@ class Runner extends Emittery {
349365 task . implementation :
350366 t => task . implementation . apply ( null , [ t ] . concat ( task . args ) ) ,
351367 compareTestSnapshot : this . boundCompareTestSnapshot ,
368+ skipSnapshot : this . boundSkipSnapshot ,
352369 updateSnapshots : this . updateSnapshots ,
353370 metadata : task . metadata ,
354371 powerAssert : this . powerAssert ,
0 commit comments