diff --git a/src/repo2rlenv/pipelines/pr_runtime.py b/src/repo2rlenv/pipelines/pr_runtime.py index e0546447..8dea6de3 100644 --- a/src/repo2rlenv/pipelines/pr_runtime.py +++ b/src/repo2rlenv/pipelines/pr_runtime.py @@ -186,6 +186,8 @@ def _reflow_pr_body(body: str) -> str: # documentation paths. _TEST_DIR_NAMES = {"test", "tests", "testing", "e2e", "__tests__"} _DOC_PREFIX_DIRS = {"docs", "doc", "documentation", "examples", "example"} +# jest/vitest's default test-file names: `*.test.ts`, `*.spec.tsx`, `*.test.mjs`, ... +_JS_TEST_FILE_RE = re.compile(r"\.(?:test|spec)\.[cm]?[jt]sx?$") def _path_is_test(path: str) -> bool: @@ -198,7 +200,8 @@ def _path_is_test(path: str) -> bool: 2. Files inside a test directory component (any path part in `_TEST_DIR_NAMES`) are test files. 3. Files with a pytest-style basename (`test_*.py`, `*_test.py`, - `*_test.go`) are test files. + `*_test.go`) or a jest/vitest one (`*.test.ts`, `*.spec.tsx`) are + test files. """ if not path: return False @@ -217,8 +220,8 @@ def _path_is_test(path: str) -> bool: basename = parts[-1] return ( (basename.startswith("test_") and basename.endswith((".py", ".js", ".ts"))) - or basename.endswith(("_test.py", "_test.go", ".test.ts", ".test.js")) - or basename.endswith((".spec.ts", ".spec.js")) + or basename.endswith(("_test.py", "_test.go")) + or _JS_TEST_FILE_RE.search(basename) is not None ) diff --git a/tests/test_pipeline_pr_runtime.py b/tests/test_pipeline_pr_runtime.py index e877ee0d..fde13583 100644 --- a/tests/test_pipeline_pr_runtime.py +++ b/tests/test_pipeline_pr_runtime.py @@ -119,6 +119,17 @@ def test_path_is_test_heuristic(): assert not _path_is_test("src/click/testing.py") +def test_path_is_test_matches_jsx_tsx_and_module_js_test_files(): + # jest and vitest pick these up by default; colocated React tests are + # usually `.test.tsx`, so missing them dropped the PR as `no_test_patch` + assert _path_is_test("src/Button.test.tsx") + assert _path_is_test("src/Button.spec.jsx") + assert _path_is_test("src/util.test.mjs") + assert _path_is_test("src/util.spec.cts") + assert not _path_is_test("src/Button.tsx") + assert not _path_is_test("src/test.config.ts") + + def test_files_in_patch_returns_unique_paths(): paths = _files_in_patch(_SAMPLE_DIFF) assert paths == ["src/foo.py", "tests/test_foo.py"]