@@ -271,7 +271,20 @@ def _get_test_patterns(self) -> list[str]:
271271 List of glob patterns for test files.
272272
273273 """
274- return ["*.test.js" , "*.test.jsx" , "*.spec.js" , "*.spec.jsx" , "__tests__/**/*.js" , "__tests__/**/*.jsx" ]
274+ return [
275+ "*.test.js" ,
276+ "*.test.jsx" ,
277+ "*.spec.js" ,
278+ "*.spec.jsx" ,
279+ "*.test.ts" ,
280+ "*.test.tsx" ,
281+ "*.spec.ts" ,
282+ "*.spec.tsx" ,
283+ "__tests__/**/*.js" ,
284+ "__tests__/**/*.jsx" ,
285+ "__tests__/**/*.ts" ,
286+ "__tests__/**/*.tsx" ,
287+ ]
275288
276289 def discover_tests (
277290 self , test_root : Path , source_functions : Sequence [FunctionToOptimize ]
@@ -280,6 +293,8 @@ def discover_tests(
280293
281294 For JavaScript, this uses static analysis to find test files
282295 and match them to source functions based on imports and function calls.
296+ Also searches for co-located test files next to source files (a common
297+ JS/TS convention where spec/test files sit alongside source files).
283298
284299 Args:
285300 test_root: Root directory containing tests.
@@ -298,6 +313,21 @@ def discover_tests(
298313 for pattern in test_patterns :
299314 test_files .extend (test_root .rglob (pattern ))
300315
316+ # Also search for co-located test files next to source files
317+ # This is a common JS/TS convention (e.g., utils.ts + utils.spec.ts in same directory)
318+ seen_paths : set [Path ] = {f .resolve () for f in test_files }
319+ source_dirs : set [Path ] = set ()
320+ for func in source_functions :
321+ if func .file_path and func .file_path .parent not in source_dirs :
322+ source_dirs .add (func .file_path .parent )
323+ for source_dir in source_dirs :
324+ for pattern in test_patterns :
325+ for test_file in source_dir .glob (pattern ):
326+ resolved = test_file .resolve ()
327+ if resolved not in seen_paths :
328+ test_files .append (test_file )
329+ seen_paths .add (resolved )
330+
301331 for test_file in test_files :
302332 try :
303333 source = test_file .read_text ()
@@ -2530,25 +2560,6 @@ def file_extensions(self) -> tuple[str, ...]:
25302560 """File extensions for TypeScript files."""
25312561 return (".ts" , ".tsx" , ".mts" )
25322562
2533- def _get_test_patterns (self ) -> list [str ]:
2534- """Get test file patterns for TypeScript.
2535-
2536- Includes TypeScript patterns plus JavaScript patterns for mixed projects.
2537-
2538- Returns:
2539- List of glob patterns for test files.
2540-
2541- """
2542- return [
2543- "*.test.ts" ,
2544- "*.test.tsx" ,
2545- "*.spec.ts" ,
2546- "*.spec.tsx" ,
2547- "__tests__/**/*.ts" ,
2548- "__tests__/**/*.tsx" ,
2549- * super ()._get_test_patterns (),
2550- ]
2551-
25522563 def get_test_file_suffix (self ) -> str :
25532564 """Get the test file suffix for TypeScript.
25542565
0 commit comments