@@ -354,7 +354,7 @@ test('watcher reruns test files when snapshot dependencies change', t => {
354354			}  else  { 
355355				passedFirst  =  true ; 
356356				setTimeout ( ( )  =>  { 
357- 					touch . sync ( path . join ( __dirname ,  'fixture/snapshots/__snapshots__/ test.js.snap' ) ) ; 
357+ 					touch . sync ( path . join ( __dirname ,  'fixture/snapshots/test.js.snap' ) ) ; 
358358				} ,  500 ) ; 
359359			} 
360360		} 
@@ -556,29 +556,39 @@ test('promise tests fail if event loop empties before they\'re resolved', t => {
556556	} ) ; 
557557} ) ; 
558558
559- test ( 'snapshots work' ,  t  =>  { 
560- 	try  { 
561- 		fs . unlinkSync ( path . join ( __dirname ,  'fixture' ,  'snapshots' ,  '__snapshots__' ,  'test.js.snap' ) ) ; 
562- 	}  catch  ( err )  { 
563- 		if  ( err . code  !==  'ENOENT' )  { 
564- 			throw  err ; 
559+ for  ( const  obj  of  [ 
560+ 	{ type : 'colocated' ,  rel : '' ,  dir : '' } , 
561+ 	{ type : '__tests__' ,  rel : '__tests__-dir' ,  dir : '__tests__/__snapshots__' } , 
562+ 	{ type : 'test' ,  rel : 'test-dir' ,  dir : 'test/snapshots' } , 
563+ 	{ type : 'tests' ,  rel : 'tests-dir' ,  dir : 'tests/snapshots' } 
564+ ] )  { 
565+ 	test ( `snapshots work (${ obj . type }  ,  t  =>  { 
566+ 		const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  obj . rel ,  obj . dir ,  'test.js.snap' ) ; 
567+ 		try  { 
568+ 			fs . unlinkSync ( snapPath ) ; 
569+ 		}  catch  ( err )  { 
570+ 			if  ( err . code  !==  'ENOENT' )  { 
571+ 				throw  err ; 
572+ 			} 
565573		} 
566- 	} 
567574
568- 	// Test should pass, and a snapshot gets written 
569- 	execCli ( [ '--update-snapshots' ,  'test.js' ] ,  { dirname : 'fixture/snapshots' } ,  err  =>  { 
570- 		t . ifError ( err ) ; 
571- 
572- 		// Test should pass, and the snapshot gets used 
573- 		execCli ( [ 'test.js' ] ,  { dirname : 'fixture/snapshots' } ,  err  =>  { 
575+ 		const  dirname  =  path . join ( 'fixture/snapshots' ,  obj . rel ) ; 
576+ 		// Test should pass, and a snapshot gets written 
577+ 		execCli ( [ '--update-snapshots' ] ,  { dirname} ,  err  =>  { 
574578			t . ifError ( err ) ; 
575- 			t . end ( ) ; 
579+ 			t . true ( fs . existsSync ( snapPath ) ) ; 
580+ 
581+ 			// Test should pass, and the snapshot gets used 
582+ 			execCli ( [ ] ,  { dirname} ,  err  =>  { 
583+ 				t . ifError ( err ) ; 
584+ 				t . end ( ) ; 
585+ 			} ) ; 
576586		} ) ; 
577587	} ) ; 
578- } ) ; 
588+ } 
579589
580590test ( 'outdated snapshot version is reported to the console' ,  t  =>  { 
581- 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  '__snapshots__'  ,   ' test.js.snap') ; 
591+ 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  'test.js.snap' ) ; 
582592	fs . writeFileSync ( snapPath ,  Buffer . from ( [ 0x0A ,  0x00 ,  0x00 ] ) ) ; 
583593
584594	execCli ( [ 'test.js' ] ,  { dirname : 'fixture/snapshots' } ,  ( err ,  stdout ,  stderr )  =>  { 
@@ -592,7 +602,7 @@ test('outdated snapshot version is reported to the console', t => {
592602} ) ; 
593603
594604test ( 'newer snapshot version is reported to the console' ,  t  =>  { 
595- 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  '__snapshots__'  ,   ' test.js.snap') ; 
605+ 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  'test.js.snap' ) ; 
596606	fs . writeFileSync ( snapPath ,  Buffer . from ( [ 0x0A ,  0xFF ,  0xFF ] ) ) ; 
597607
598608	execCli ( [ 'test.js' ] ,  { dirname : 'fixture/snapshots' } ,  ( err ,  stdout ,  stderr )  =>  { 
@@ -606,7 +616,7 @@ test('newer snapshot version is reported to the console', t => {
606616} ) ; 
607617
608618test ( 'snapshot corruption is reported to the console' ,  t  =>  { 
609- 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  '__snapshots__'  ,   ' test.js.snap') ; 
619+ 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  'test.js.snap' ) ; 
610620	fs . writeFileSync ( snapPath ,  Buffer . from ( [ 0x0A ,  0x01 ,  0x00 ] ) ) ; 
611621
612622	execCli ( [ 'test.js' ] ,  { dirname : 'fixture/snapshots' } ,  ( err ,  stdout ,  stderr )  =>  { 
@@ -620,7 +630,7 @@ test('snapshot corruption is reported to the console', t => {
620630} ) ; 
621631
622632test ( 'legacy snapshot files are reported to the console' ,  t  =>  { 
623- 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  '__snapshots__'  ,   ' test.js.snap') ; 
633+ 	const  snapPath  =  path . join ( __dirname ,  'fixture' ,  'snapshots' ,  'test.js.snap' ) ; 
624634	fs . writeFileSync ( snapPath ,  Buffer . from ( '// Jest Snapshot v1, https://goo.gl/fbAQLP\n' ) ) ; 
625635
626636	execCli ( [ 'test.js' ] ,  { dirname : 'fixture/snapshots' } ,  ( err ,  stdout ,  stderr )  =>  { 
0 commit comments