@@ -65,6 +65,7 @@ jest.doMock(
6565const watch = require ( '../watch' ) . default ;
6666
6767const nextTick = ( ) => new Promise ( res => process . nextTick ( res ) ) ;
68+ const toHex = char => Number ( char . charCodeAt ( 0 ) ) . toString ( 16 ) ;
6869
6970afterEach ( runJestMock . mockReset ) ;
7071
@@ -410,6 +411,68 @@ describe('Watch mode flows', () => {
410411 expect ( runJestMock ) . toHaveBeenCalledTimes ( 2 ) ;
411412 } ) ;
412413
414+ it ( 'Pressing "t" reruns the tests in "test name pattern" mode' , async ( ) => {
415+ const hooks = new JestHooks ( ) ;
416+
417+ watch ( globalConfig , contexts , pipe , hasteMapInstances , stdin , hooks ) ;
418+ runJestMock . mockReset ( ) ;
419+
420+ stdin . emit ( KEYS . T ) ;
421+ [ 't' , 'e' , 's' , 't' ] . map ( toHex ) . forEach ( key => stdin . emit ( key ) ) ;
422+ stdin . emit ( KEYS . ENTER ) ;
423+ await nextTick ( ) ;
424+
425+ expect ( runJestMock . mock . calls [ 0 ] [ 0 ] . globalConfig ) . toMatchObject ( {
426+ testNamePattern : 'test' ,
427+ testPathPattern : '' ,
428+ watch : true ,
429+ watchAll : false ,
430+ } ) ;
431+ } ) ;
432+
433+ it ( 'Pressing "p" reruns the tests in "filename pattern" mode' , async ( ) => {
434+ const hooks = new JestHooks ( ) ;
435+
436+ watch ( globalConfig , contexts , pipe , hasteMapInstances , stdin , hooks ) ;
437+ runJestMock . mockReset ( ) ;
438+
439+ stdin . emit ( KEYS . P ) ;
440+ [ 'f' , 'i' , 'l' , 'e' ] . map ( toHex ) . forEach ( key => stdin . emit ( key ) ) ;
441+ stdin . emit ( KEYS . ENTER ) ;
442+ await nextTick ( ) ;
443+
444+ expect ( runJestMock . mock . calls [ 0 ] [ 0 ] . globalConfig ) . toMatchObject ( {
445+ testNamePattern : '' ,
446+ testPathPattern : 'file' ,
447+ watch : true ,
448+ watchAll : false ,
449+ } ) ;
450+ } ) ;
451+
452+ it ( 'Can combine "p" and "t" filters' , async ( ) => {
453+ const hooks = new JestHooks ( ) ;
454+
455+ watch ( globalConfig , contexts , pipe , hasteMapInstances , stdin , hooks ) ;
456+ runJestMock . mockReset ( ) ;
457+
458+ stdin . emit ( KEYS . P ) ;
459+ [ 'f' , 'i' , 'l' , 'e' ] . map ( toHex ) . forEach ( key => stdin . emit ( key ) ) ;
460+ stdin . emit ( KEYS . ENTER ) ;
461+ await nextTick ( ) ;
462+
463+ stdin . emit ( KEYS . T ) ;
464+ [ 't' , 'e' , 's' , 't' ] . map ( toHex ) . forEach ( key => stdin . emit ( key ) ) ;
465+ stdin . emit ( KEYS . ENTER ) ;
466+ await nextTick ( ) ;
467+
468+ expect ( runJestMock . mock . calls [ 1 ] [ 0 ] . globalConfig ) . toMatchObject ( {
469+ testNamePattern : 'test' ,
470+ testPathPattern : 'file' ,
471+ watch : true ,
472+ watchAll : false ,
473+ } ) ;
474+ } ) ;
475+
413476 it ( 'Pressing "u" reruns the tests in "update snapshot" mode' , async ( ) => {
414477 const hooks = new JestHooks ( ) ;
415478
@@ -426,14 +489,32 @@ describe('Watch mode flows', () => {
426489 expect ( runJestMock . mock . calls [ 0 ] [ 0 ] . globalConfig ) . toMatchObject ( {
427490 updateSnapshot : 'all' ,
428491 watch : true ,
492+ watchAll : false ,
429493 } ) ;
430494
431495 stdin . emit ( KEYS . A ) ;
496+
432497 await nextTick ( ) ;
433498 // updateSnapshot is not sticky after a run.
434499 expect ( runJestMock . mock . calls [ 1 ] [ 0 ] . globalConfig ) . toMatchObject ( {
435500 updateSnapshot : 'new' ,
436501 watch : false ,
502+ watchAll : true ,
503+ } ) ;
504+
505+ results = { snapshot : { failure : true } } ;
506+
507+ stdin . emit ( KEYS . A ) ;
508+ await nextTick ( ) ;
509+
510+ runJestMock . mockReset ( ) ;
511+ stdin . emit ( KEYS . U ) ;
512+ await nextTick ( ) ;
513+
514+ expect ( runJestMock . mock . calls [ 0 ] [ 0 ] . globalConfig ) . toMatchObject ( {
515+ updateSnapshot : 'all' ,
516+ watch : false ,
517+ watchAll : true ,
437518 } ) ;
438519 } ) ;
439520
0 commit comments