Skip to content

Commit 1e97f0f

Browse files
feat: add __tests__ to test file detection defaults (#24443)
The `jest` test runner popularized putting tests into a `__tests__` folder. Whilst many have switched to going with a `.test` suffix in the file name these days, there are still many jest projects that have `__tests__`. By adding this to the default test detection logic it makes `deno test` discover those out of the box.
1 parent 74ac29b commit 1e97f0f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cli/args/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,7 @@ report results to standard output:
25912591
deno test src/fetch_test.ts src/signal_test.ts
25922592
25932593
Directory arguments are expanded to all contained files matching the glob
2594-
{*_,*.,}test.{js,mjs,ts,mts,jsx,tsx}:
2594+
{*_,*.,}test.{js,mjs,ts,mts,jsx,tsx} or **/__tests__/**:
25952595
25962596
deno test src/",
25972597
)

cli/tools/test/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,9 +1611,16 @@ pub(crate) fn is_supported_test_path(path: &Path) -> bool {
16111611
fn has_supported_test_path_name(path: &Path) -> bool {
16121612
if let Some(name) = path.file_stem() {
16131613
let basename = name.to_string_lossy();
1614-
basename.ends_with("_test")
1614+
if basename.ends_with("_test")
16151615
|| basename.ends_with(".test")
16161616
|| basename == "test"
1617+
{
1618+
return true;
1619+
}
1620+
1621+
path
1622+
.components()
1623+
.any(|seg| seg.as_os_str().to_str() == Some("__tests__"))
16171624
} else {
16181625
false
16191626
}
@@ -2077,6 +2084,18 @@ mod inner_test {
20772084
assert!(is_supported_test_path(Path::new("foo/bar/test.jsx")));
20782085
assert!(is_supported_test_path(Path::new("foo/bar/test.ts")));
20792086
assert!(is_supported_test_path(Path::new("foo/bar/test.tsx")));
2087+
assert!(is_supported_test_path(Path::new(
2088+
"foo/bar/__tests__/foo.js"
2089+
)));
2090+
assert!(is_supported_test_path(Path::new(
2091+
"foo/bar/__tests__/foo.jsx"
2092+
)));
2093+
assert!(is_supported_test_path(Path::new(
2094+
"foo/bar/__tests__/foo.ts"
2095+
)));
2096+
assert!(is_supported_test_path(Path::new(
2097+
"foo/bar/__tests__/foo.tsx"
2098+
)));
20802099
assert!(!is_supported_test_path(Path::new("README.md")));
20812100
assert!(!is_supported_test_path(Path::new("lib/typescript.d.ts")));
20822101
assert!(!is_supported_test_path(Path::new("notatest.js")));

0 commit comments

Comments
 (0)