@@ -130,6 +130,54 @@ test('handles property matchers', () => {
130130 }
131131} ) ;
132132
133+ test ( 'removes obsolete external snapshots' , ( ) => {
134+ const filename = 'removes-obsolete-external-snapshots.test.js' ;
135+ const snapshotPath = path . join (
136+ TESTS_DIR ,
137+ '__snapshots__' ,
138+ filename + '.snap' ,
139+ ) ;
140+ const template = makeTemplate ( `
141+ test('removes obsolete external snapshots', () => {
142+ expect('1').$1();
143+ });
144+ ` ) ;
145+
146+ {
147+ writeFiles ( TESTS_DIR , { [ filename ] : template ( [ 'toMatchSnapshot' ] ) } ) ;
148+ const { stderr, status} = runJest ( DIR , [ '-w=1' , '--ci=false' , filename ] ) ;
149+ const fileAfter = readFile ( filename ) ;
150+ expect ( stderr ) . toMatch ( '1 snapshot written from 1 test suite.' ) ;
151+ expect ( status ) . toBe ( 0 ) ;
152+ expect ( fileAfter ) . toMatchSnapshot ( 'initial write' ) ;
153+ expect ( fs . existsSync ( snapshotPath ) ) . toEqual ( true ) ;
154+ }
155+
156+ {
157+ writeFiles ( TESTS_DIR , { [ filename ] : template ( [ 'toMatchInlineSnapshot' ] ) } ) ;
158+ const { stderr, status} = runJest ( DIR , [ '-w=1' , '--ci=false' , filename ] ) ;
159+ const fileAfter = readFile ( filename ) ;
160+ expect ( stderr ) . toMatch ( 'Snapshots: 1 obsolete, 1 written, 1 total' ) ;
161+ expect ( status ) . toBe ( 1 ) ;
162+ expect ( fileAfter ) . toMatchSnapshot ( 'inline snapshot written' ) ;
163+ expect ( fs . existsSync ( snapshotPath ) ) . toEqual ( true ) ;
164+ }
165+
166+ {
167+ const { stderr, status} = runJest ( DIR , [
168+ '-w=1' ,
169+ '--ci=false' ,
170+ filename ,
171+ '-u' ,
172+ ] ) ;
173+ const fileAfter = readFile ( filename ) ;
174+ expect ( stderr ) . toMatch ( 'Snapshots: 1 file removed, 1 passed, 1 total' ) ;
175+ expect ( status ) . toBe ( 0 ) ;
176+ expect ( fileAfter ) . toMatchSnapshot ( 'external snapshot cleaned' ) ;
177+ expect ( fs . existsSync ( snapshotPath ) ) . toEqual ( false ) ;
178+ }
179+ } ) ;
180+
133181test ( 'supports async matchers' , ( ) => {
134182 const filename = 'async-matchers.test.js' ;
135183 const test = `
0 commit comments