import * as expand from 'glob-expand' ; import { Test } from './' ; import { join } from 'path' ; const defaultPatterns = [ /.*\.(spec|test)\.(js|ts)$/ , /-(spec|test)\.(js|ts)$/ , /(Spec|Test)\.(js|ts)$/ , 'test/**/*.js' , 'test/**/*.ts' , 'tests/**/*.js' , 'tests/**/*.ts' , '!lib/**/*.*' , '!lib.es2015/**/*.*' , '!node_modules/**/*.*' , ] ; export function findAllTests ( testFiles = defaultPatterns ) { const cwd = process . cwd ( ) ; const files = expand ( { filter : 'isFile' , cwd : cwd } , testFiles ) ; const filePaths = files . map ( function ( file ) { return join ( cwd , file ) ; } ) ; const tests = [ ] ; filePaths . forEach ( function ( path ) { const pkg = require ( path ) ; if ( isTest ( pkg ) ) tests . push ( pkg ) ; Object . keys ( pkg ) . forEach ( function ( key ) { const value = pkg [ key ] ; if ( isTest ( value ) ) tests . push ( value ) ; } ) ; } ) ; return tests ; } function isTest ( x ) { return x && typeof x . name === 'string' && typeof x . run === 'function' ; }