@@ -587,6 +587,42 @@ for (const obj of [
587
587
} ) ;
588
588
}
589
589
590
+ test ( 'appends to existing snapshots' , t => {
591
+ const cliPath = require . resolve ( '../cli.js' ) ;
592
+ const avaPath = require . resolve ( '../' ) ;
593
+
594
+ const cwd = uniqueTempDir ( { create : true } ) ;
595
+ fs . writeFileSync ( path . join ( cwd , 'package.json' ) , '{}' ) ;
596
+
597
+ const initial = `import test from ${ JSON . stringify ( avaPath ) }
598
+ test('one', t => {
599
+ t.snapshot({one: true})
600
+ })` ;
601
+ fs . writeFileSync ( path . join ( cwd , 'test.js' ) , initial ) ;
602
+
603
+ const run = ( ) => execa ( process . execPath , [ cliPath , '--verbose' , '--no-color' ] , { cwd, reject : false } ) ;
604
+ return run ( ) . then ( result => {
605
+ t . match ( result . stderr , / 1 t e s t p a s s e d / ) ;
606
+
607
+ fs . writeFileSync ( path . join ( cwd , 'test.js' ) , `${ initial }
608
+ test('two', t => {
609
+ t.snapshot({two: true})
610
+ })` ) ;
611
+ return run ( ) ;
612
+ } ) . then ( result => {
613
+ t . match ( result . stderr , / 2 t e s t s p a s s e d / ) ;
614
+
615
+ fs . writeFileSync ( path . join ( cwd , 'test.js' ) , `${ initial }
616
+ test('two', t => {
617
+ t.snapshot({two: false})
618
+ })` ) ;
619
+
620
+ return run ( ) ;
621
+ } ) . then ( result => {
622
+ t . match ( result . stderr , / 1 t e s t f a i l e d / ) ;
623
+ } ) ;
624
+ } ) ;
625
+
590
626
test ( 'outdated snapshot version is reported to the console' , t => {
591
627
const snapPath = path . join ( __dirname , 'fixture' , 'snapshots' , 'test.js.snap' ) ;
592
628
fs . writeFileSync ( snapPath , Buffer . from ( [ 0x0A , 0x00 , 0x00 ] ) ) ;
0 commit comments