Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions codeflash/languages/javascript/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ def discover_tests(
"""
result: dict[str, list[TestInfo]] = {}

# Build index: function_name → qualified_name for O(1) lookup
# This avoids iterating all functions for every test file (was O(NxM), now O(N+M))
function_name_to_qualified: dict[str, str] = {}
for func in source_functions:
function_name_to_qualified[func.function_name] = func.qualified_name

# Find all test files using language-specific patterns
test_patterns = self._get_test_patterns()

Expand All @@ -254,13 +260,15 @@ def discover_tests(
# Find test functions (describe/it/test blocks)
test_functions = self._find_jest_tests(source, analyzer)

# Match source functions to tests
for func in source_functions:
if func.function_name in imported_names or func.function_name in source:
if func.qualified_name not in result:
result[func.qualified_name] = []
# Match source functions to tests using the index
# Only check functions that are actually imported in this test file
for imported_name in imported_names:
if imported_name in function_name_to_qualified:
qualified_name = function_name_to_qualified[imported_name]
if qualified_name not in result:
result[qualified_name] = []
for test_name in test_functions:
result[func.qualified_name].append(
result[qualified_name].append(
TestInfo(test_name=test_name, test_file=test_file, test_class=None)
)
except Exception as e:
Expand Down
Loading