44 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
66 *
7- * @flow
87 */
98
109import util from 'util' ;
@@ -15,8 +14,8 @@ import {ErrorWithStack} from 'jest-util';
1514
1615type Table = Array < Array < any > > ;
1716type PrettyArgs = {
18- args : Array < mixed > ,
19- title : string ,
17+ args : Array < any > ;
18+ title : string ;
2019} ;
2120
2221const EXPECTED_COLOR = chalk . green ;
@@ -26,7 +25,7 @@ const PRETTY_PLACEHOLDER = '%p';
2625const INDEX_PLACEHOLDER = '%#' ;
2726
2827export default ( cb : Function , supportsDone : boolean = true ) => ( ...args : any ) =>
29- function eachBind ( title : string , test : Function , timeout : number ) : void {
28+ function eachBind ( title : string , test : Function , timeout ? : number ) : void {
3029 if ( args . length === 1 ) {
3130 const [ tableArg ] = args ;
3231
@@ -122,19 +121,20 @@ export default (cb: Function, supportsDone: boolean = true) => (...args: any) =>
122121 ) ;
123122 } ;
124123
125- const isTaggedTemplateLiteral = array => array . raw !== undefined ;
126- const isEmptyTable = table => table . length === 0 ;
127- const isEmptyString = str => typeof str === 'string' && str . trim ( ) === '' ;
124+ const isTaggedTemplateLiteral = ( array : any ) => array . raw !== undefined ;
125+ const isEmptyTable = ( table : Array < any > ) => table . length === 0 ;
126+ const isEmptyString = ( str : string ) =>
127+ typeof str === 'string' && str . trim ( ) === '' ;
128128
129- const getPrettyIndexes = placeholders =>
130- placeholders . reduce ( ( indexes , placeholder , index ) => {
129+ const getPrettyIndexes = ( placeholders : RegExpMatchArray ) =>
130+ placeholders . reduce ( ( indexes : Array < number > , placeholder , index ) => {
131131 if ( placeholder === PRETTY_PLACEHOLDER ) {
132132 indexes . push ( index ) ;
133133 }
134134 return indexes ;
135135 } , [ ] ) ;
136136
137- const arrayFormat = ( title , rowIndex , ...args ) => {
137+ const arrayFormat = ( title : string , rowIndex : number , ...args : Array < any > ) => {
138138 const placeholders = title . match ( SUPPORTED_PLACEHOLDERS ) || [ ] ;
139139 const prettyIndexes = getPrettyIndexes ( placeholders ) ;
140140
@@ -164,13 +164,15 @@ const arrayFormat = (title, rowIndex, ...args) => {
164164 ) ;
165165} ;
166166
167+ type Done = ( ) => { } ;
168+
167169const applyRestParams = (
168170 supportsDone : boolean ,
169171 params : Array < any > ,
170172 test : Function ,
171173) =>
172174 supportsDone && params . length < test . length
173- ? done => test ( ...params , done )
175+ ? ( done : Done ) => test ( ...params , done )
174176 : ( ) => test ( ...params ) ;
175177
176178const getHeadingKeys = ( headings : string ) : Array < string > =>
@@ -190,10 +192,15 @@ const buildTable = (
190192 ) ,
191193 ) ;
192194
193- const getMatchingKeyPaths = title => ( matches , key ) =>
194- matches . concat ( title . match ( new RegExp ( `\\$${ key } [\\.\\w]*` , 'g' ) ) || [ ] ) ;
195+ const getMatchingKeyPaths = ( title : string ) => (
196+ matches : Array < string > ,
197+ key : string ,
198+ ) => matches . concat ( title . match ( new RegExp ( `\\$${ key } [\\.\\w]*` , 'g' ) ) || [ ] ) ;
195199
196- const replaceKeyPathWithValue = data => ( title , match ) => {
200+ const replaceKeyPathWithValue = ( data : any ) => (
201+ title : string ,
202+ match : string ,
203+ ) => {
197204 const keyPath = match . replace ( '$' , '' ) . split ( '.' ) ;
198205 const value = getPath ( data , keyPath ) ;
199206
@@ -209,12 +216,17 @@ const interpolate = (title: string, data: any) =>
209216 . reduce ( replaceKeyPathWithValue ( data ) , title ) ;
210217
211218const applyObjectParams = ( supportsDone : boolean , obj : any , test : Function ) =>
212- supportsDone && test . length > 1 ? done => test ( obj , done ) : ( ) => test ( obj ) ;
219+ supportsDone && test . length > 1
220+ ? ( done : Done ) => test ( obj , done )
221+ : ( ) => test ( obj ) ;
213222
214223const pluralize = ( word : string , count : number ) =>
215224 word + ( count === 1 ? '' : 's' ) ;
216225
217- const getPath = ( o : Object , [ head , ...tail ] : Array < string > ) => {
226+ const getPath = (
227+ o : { [ key : string ] : any } ,
228+ [ head , ...tail ] : Array < string > ,
229+ ) : any => {
218230 if ( ! head || ! o . hasOwnProperty || ! o . hasOwnProperty ( head ) ) return o ;
219231 return getPath ( o [ head ] , tail ) ;
220232} ;
0 commit comments