@@ -13,6 +13,7 @@ import type {Glob, Path} from 'types/Config';
1313import type { ResolveModuleConfig } from 'types/Resolve' ;
1414import type { Test } from 'types/TestRunner' ;
1515
16+ import fs from 'fs' ;
1617import path from 'path' ;
1718import micromatch from 'micromatch' ;
1819import DependencyResolver from 'jest-resolve-dependencies' ;
@@ -76,6 +77,15 @@ const toTests = (context, tests) =>
7677 path,
7778 } ) ) ;
7879
80+ const fileExists = ( filePath : string ) => {
81+ try {
82+ fs . accessSync ( filePath , fs . F_OK ) ;
83+ return true ;
84+ } catch ( e ) {
85+ return false ;
86+ }
87+ } ;
88+
7989class SearchSource {
8090 _context : Context ;
8191 _options : ResolveModuleConfig ;
@@ -230,12 +240,16 @@ class SearchSource {
230240 return Promise . resolve (
231241 this . findRelatedTestsFromPattern ( testSelectionConfig . paths ) ,
232242 ) ;
233- } else if ( testSelectionConfig . testPathPattern != null ) {
234- return Promise . resolve (
235- this . findMatchingTests ( testSelectionConfig . testPathPattern ) ,
236- ) ;
237243 } else {
238- return Promise . resolve ( { tests : [ ] } ) ;
244+ const validTestPaths = testSelectionConfig . paths && testSelectionConfig . paths . filter ( fileExists ) ;
245+
246+ if ( validTestPaths && validTestPaths . length ) {
247+ return Promise . resolve ( { tests : toTests ( this . _context , validTestPaths ) } ) ;
248+ } else if ( testSelectionConfig . testPathPattern != null ) {
249+ return Promise . resolve ( this . findMatchingTests ( testSelectionConfig . testPathPattern ) ) ;
250+ } else {
251+ return Promise . resolve ( { tests : [ ] } ) ;
252+ }
239253 }
240254 }
241255}
0 commit comments