@@ -61,16 +61,11 @@ export type PatternInfo = {|
6161const git = changedFiles . git ;
6262const hg = changedFiles . hg ;
6363
64- const determineSCM = path => Promise . all ( [
65- git . isGitRepository ( path ) ,
66- hg . isHGRepository ( path ) ,
67- ] ) ;
64+ const determineSCM = path =>
65+ Promise . all ( [ git . isGitRepository ( path ) , hg . isHGRepository ( path ) ] ) ;
6866const pathToRegex = p => replacePathSepForRegex ( p ) ;
69- const pluralize = (
70- word : string ,
71- count : number ,
72- ending : string ,
73- ) => `${ count } ${ word } ${ count === 1 ? '' : ending } ` ;
67+ const pluralize = ( word : string , count : number , ending : string ) =>
68+ `${ count } ${ word } ${ count === 1 ? '' : ending } ` ;
7469
7570const globsToMatcher = ( globs : ?Array < Glob > ) => {
7671 if ( globs == null || globs . length === 0 ) {
@@ -114,22 +109,20 @@ class SearchSource {
114109 skipNodeResolution : false ,
115110 } ;
116111
117- this . _rootPattern =
118- new RegExp ( config . roots . map (
119- dir => escapePathForRegex ( dir ) ,
120- ) . join ( '|' ) ) ;
112+ this . _rootPattern = new RegExp (
113+ config . roots . map ( dir => escapePathForRegex ( dir ) ) . join ( '|' ) ,
114+ ) ;
121115
122116 const ignorePattern = config . testPathIgnorePatterns ;
123- this . _testIgnorePattern =
124- ignorePattern . length ? new RegExp ( ignorePattern . join ( '|' ) ) : null ;
117+ this . _testIgnorePattern = ignorePattern . length
118+ ? new RegExp ( ignorePattern . join ( '|' ) )
119+ : null ;
125120
126121 this . _testPathCases = {
127122 roots : path => this . _rootPattern . test ( path ) ,
128123 testMatch : globsToMatcher ( config . testMatch ) ,
129- testPathIgnorePatterns : path => (
130- ! this . _testIgnorePattern ||
131- ! this . _testIgnorePattern . test ( path )
132- ) ,
124+ testPathIgnorePatterns : path =>
125+ ! this . _testIgnorePattern || ! this . _testIgnorePattern . test ( path ) ,
133126 testRegex : regexToMatcher ( config . testRegex ) ,
134127 } ;
135128 }
@@ -153,37 +146,35 @@ class SearchSource {
153146 const testCasesKeys = Object . keys ( testCases ) ;
154147
155148 data . paths = allPaths . filter ( path => {
156- return testCasesKeys . reduce ( ( flag , key ) => {
157- if ( testCases [ key ] ( path ) ) {
158- data . stats [ key ] = ++ data . stats [ key ] || 1 ;
159- return flag && true ;
160- }
161- data . stats [ key ] = data . stats [ key ] || 0 ;
162- return false ;
163- } , true ) ;
149+ return testCasesKeys . reduce (
150+ ( flag , key ) => {
151+ if ( testCases [ key ] ( path ) ) {
152+ data . stats [ key ] = ++ data . stats [ key ] || 1 ;
153+ return flag && true ;
154+ }
155+ data . stats [ key ] = data . stats [ key ] || 0 ;
156+ return false ;
157+ } ,
158+ true ,
159+ ) ;
164160 } ) ;
165161
166162 return data ;
167163 }
168164
169- _getAllTestPaths (
170- testPathPattern : StrOrRegExpPattern ,
171- ) : SearchResult {
165+ _getAllTestPaths ( testPathPattern : StrOrRegExpPattern ) : SearchResult {
172166 return this . _filterTestPathsWithStats (
173167 this . _hasteContext . hasteFS . getAllFiles ( ) ,
174168 testPathPattern ,
175169 ) ;
176170 }
177171
178172 isTestFilePath ( path : Path ) : boolean {
179- return Object . keys ( this . _testPathCases ) . every ( key => (
180- this . _testPathCases [ key ] ( path )
181- ) ) ;
173+ return Object . keys ( this . _testPathCases ) . every ( key =>
174+ this . _testPathCases [ key ] ( path ) ) ;
182175 }
183176
184- findMatchingTests (
185- testPathPattern : StrOrRegExpPattern ,
186- ) : SearchResult {
177+ findMatchingTests ( testPathPattern : StrOrRegExpPattern ) : SearchResult {
187178 return this . _getAllTestPaths ( testPathPattern ) ;
188179 }
189180
@@ -203,9 +194,7 @@ class SearchSource {
203194 } ;
204195 }
205196
206- findRelatedTestsFromPattern (
207- paths : Array < Path > ,
208- ) : SearchResult {
197+ findRelatedTestsFromPattern ( paths : Array < Path > ) : SearchResult {
209198 if ( Array . isArray ( paths ) && paths . length ) {
210199 const resolvedPaths = paths . map ( p => path . resolve ( process . cwd ( ) , p ) ) ;
211200 return this . findRelatedTests ( new Set ( resolvedPaths ) ) ;
@@ -214,22 +203,24 @@ class SearchSource {
214203 }
215204
216205 findChangedTests ( options : Options ) : Promise < SearchResult > {
217- return Promise . all ( this . _config . roots . map ( determineSCM ) )
218- . then ( repos => {
219- if ( ! repos . every ( ( [ gitRepo , hgRepo ] ) => gitRepo || hgRepo ) ) {
220- return {
221- noSCM : true ,
222- paths : [ ] ,
223- } ;
224- }
225- return Promise . all ( Array . from ( repos ) . map ( ( [ gitRepo , hgRepo ] ) => {
206+ return Promise . all ( this . _config . roots . map ( determineSCM ) ) . then ( repos => {
207+ if ( ! repos . every ( ( [ gitRepo , hgRepo ] ) => gitRepo || hgRepo ) ) {
208+ return {
209+ noSCM : true ,
210+ paths : [ ] ,
211+ } ;
212+ }
213+ return Promise . all (
214+ Array . from ( repos ) . map ( ( [ gitRepo , hgRepo ] ) => {
226215 return gitRepo
227216 ? git . findChangedFiles ( gitRepo , options )
228217 : hg . findChangedFiles ( hgRepo , options ) ;
229- } ) ) . then ( changedPathSets => this . findRelatedTests (
218+ } ) ,
219+ ) . then ( changedPathSets =>
220+ this . findRelatedTests (
230221 new Set ( Array . prototype . concat . apply ( [ ] , changedPathSets ) ) ,
231222 ) ) ;
232- } ) ;
223+ } ) ;
233224 }
234225
235226 getNoTestsFoundMessage (
@@ -238,40 +229,40 @@ class SearchSource {
238229 data : SearchResult ,
239230 ) : string {
240231 if ( patternInfo . onlyChanged ) {
241- return (
242- chalk . bold (
243- 'No tests found related to files changed since last commit.\n' ,
244- ) +
232+ return chalk . bold (
233+ 'No tests found related to files changed since last commit.\n' ,
234+ ) +
245235 chalk . dim (
246- patternInfo . watch ?
247- 'Press `a` to run all tests, or run Jest with `--watchAll`.' :
248- 'Run Jest without `-o` to run all tests.' ,
249- )
250- ) ;
236+ patternInfo . watch
237+ ? 'Press `a` to run all tests, or run Jest with `--watchAll`.'
238+ : 'Run Jest without `-o` to run all tests.' ,
239+ ) ;
251240 }
252241
253242 const testPathPattern = SearchSource . getTestPathPattern ( patternInfo ) ;
254243 const stats = data . stats || { } ;
255- const statsMessage = Object . keys ( stats ) . map ( key => {
256- const value = key === 'testPathPattern' ? testPathPattern : config [ key ] ;
257- if ( value ) {
258- const matches = pluralize ( 'match' , stats [ key ] , 'es' ) ;
259- return ` ${ key } : ${ chalk . yellow ( value ) } - ${ matches } ` ;
260- }
261- return null ;
262- } ) . filter ( line => line ) . join ( '\n' ) ;
244+ const statsMessage = Object . keys ( stats )
245+ . map ( key => {
246+ const value = key === 'testPathPattern' ? testPathPattern : config [ key ] ;
247+ if ( value ) {
248+ const matches = pluralize ( 'match' , stats [ key ] , 'es' ) ;
249+ return ` ${ key } : ${ chalk . yellow ( value ) } - ${ matches } ` ;
250+ }
251+ return null ;
252+ } )
253+ . filter ( line => line )
254+ . join ( '\n' ) ;
263255
264- return (
265- chalk . bold ( 'No tests found' ) + '\n' +
256+ return chalk . bold ( 'No tests found' ) +
257+ '\n' +
266258 ( data . total
267259 ? ` ${ pluralize ( 'file' , data . total || 0 , 's' ) } checked.\n` +
268- statsMessage
260+ statsMessage
269261 : `No files found in ${ config . rootDir } .\n` +
270- `Make sure Jest's configuration does not exclude this directory.\n` +
271- `To set up Jest, make sure a package.json file exists.\n` +
272- `Jest Documentation: facebook.github.io/jest/docs/configuration.html`
273- )
274- ) ;
262+ `Make sure Jest's configuration does not exclude this directory.` +
263+ `\nTo set up Jest, make sure a package.json file exists.\n` +
264+ `Jest Documentation: ` +
265+ `facebook.github.io/jest/docs/configuration.html` ) ;
275266 }
276267
277268 getTestPaths ( patternInfo : PatternInfo ) : Promise < SearchResult > {
@@ -297,9 +288,8 @@ class SearchSource {
297288 const formattedInput = patternInfo . shouldTreatInputAsPattern
298289 ? `/${ input || '' } /`
299290 : `"${ input || '' } "` ;
300- return ( input === pattern ) ? formattedInput : formattedPattern ;
291+ return input === pattern ? formattedInput : formattedPattern ;
301292 }
302-
303293}
304294
305295module . exports = SearchSource ;
0 commit comments