Skip to content
Draft
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions src/repo2rlenv/pipelines/pr_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
)


Expand Down
11 changes: 11 additions & 0 deletions tests/test_pipeline_pr_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down