Skip to content

Commit 2d5b33a

Browse files
committed
strict tests for extractor and replacer
1 parent 2cc1fb2 commit 2d5b33a

5 files changed

Lines changed: 565 additions & 417 deletions

File tree

codeflash/languages/javascript/module_system.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ def convert_esm_to_commonjs(code: str) -> str:
263263
"""
264264
import re
265265

266-
# Pattern for named import: import { a, b } from '...'
267-
named_import = re.compile(r"import\s+\{\s*([^}]+)\s*\}\s+from\s+['\"]([^'\"]+)['\"]")
266+
# Pattern for named import: import { a, b } from '...'; (semicolon optional)
267+
named_import = re.compile(r"import\s+\{\s*([^}]+)\s*\}\s+from\s+['\"]([^'\"]+)['\"];?")
268268

269-
# Pattern for default import: import foo from '...'
270-
default_import = re.compile(r"import\s+(\w+)\s+from\s+['\"]([^'\"]+)['\"]")
269+
# Pattern for default import: import foo from '...'; (semicolon optional)
270+
default_import = re.compile(r"import\s+(\w+)\s+from\s+['\"]([^'\"]+)['\"];?")
271271

272272
# Replace named imports with destructured requires
273273
def replace_named(match):

tests/test_javascript_function_discovery.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ def test_get_functions_from_file(self, tmp_path):
337337
test_config = TestConfig(
338338
tests_root=str(tmp_path / "tests"),
339339
project_root_path=str(tmp_path),
340-
test_framework="jest",
341340
tests_project_rootdir=tmp_path / "tests",
342341
)
343342

@@ -372,7 +371,6 @@ def test_get_specific_function(self, tmp_path):
372371
test_config = TestConfig(
373372
tests_root=str(tmp_path / "tests"),
374373
project_root_path=str(tmp_path),
375-
test_framework="jest",
376374
tests_project_rootdir=tmp_path / "tests",
377375
)
378376

@@ -411,7 +409,6 @@ class Calculator {
411409
test_config = TestConfig(
412410
tests_root=str(tmp_path / "tests"),
413411
project_root_path=str(tmp_path),
414-
test_framework="jest",
415412
tests_project_rootdir=tmp_path / "tests",
416413
)
417414

@@ -451,7 +448,7 @@ def test_discover_all_js_functions(self, tmp_path):
451448
# Create a non-JS file that should be ignored
452449
(tmp_path / "readme.txt").write_text("This is not code")
453450

454-
functions = get_all_files_and_functions(tmp_path, language=Language.JAVASCRIPT)
451+
functions = get_all_files_and_functions(tmp_path, ignore_paths=[], language=Language.JAVASCRIPT)
455452

456453
assert len(functions) == 2
457454
all_names = set()
@@ -473,7 +470,7 @@ def py_func():
473470
}
474471
""")
475472

476-
functions = get_all_files_and_functions(tmp_path, language=None)
473+
functions = get_all_files_and_functions(tmp_path, ignore_paths=[], language=None)
477474

478475
assert len(functions) == 2
479476

0 commit comments

Comments
 (0)