18 lines
1.0 KiB
Python
18 lines
1.0 KiB
Python
"""Which files PHPUnit and `node --test` find as tests by their names, beyond the ones `mutate_changes.changed_lines.is_test` tells.
|
|
`is_test` stays as it is: changing it would change what `mutate-changes` skips."""
|
|
import posixpath
|
|
import re
|
|
|
|
from mutate_changes.changed_lines import is_test
|
|
|
|
# The suffixes `node --test` runs: JavaScript, and TypeScript where Node strips the types; not `.jsx` or `.tsx`, which it doesn't find.
|
|
NODE_SUFFIXES = (".cjs", ".cts", ".js", ".mjs", ".mts", ".ts")
|
|
# PHPUnit's default suffix, wherever the file stands; node --test's `*-test`, `*_test`, `test-*` and `test` stems, in each of its
|
|
# suffixes. node --test's `*.test.*` is `is_test`'s already.
|
|
FRAMEWORK_NAME = re.compile(rf".*Test\.php|(?:.*[-_]test|test|test-.*)(?:{'|'.join(re.escape(suffix) for suffix in NODE_SUFFIXES)})")
|
|
|
|
|
|
def is_test_file(path: str) -> bool:
|
|
"""Whether path is a test by its name or folder alone, as `is_test`, PHPUnit or `node --test` tells it."""
|
|
return is_test(path) or bool(FRAMEWORK_NAME.fullmatch(posixpath.basename(path)))
|