diff options
author | Marvin Hagemeister <marvin@deno.com> | 2024-07-08 15:19:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-08 15:19:59 +0200 |
commit | 1e97f0f1487d27b69d85ebe8e9d84c21af1d9dde (patch) | |
tree | e8a53b37692f67e0c8570fe29f172ae401a057ba /cli/tools/test | |
parent | 74ac29bae666cd910c6f66d47b20e3209afc1fe7 (diff) |
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.
Diffstat (limited to 'cli/tools/test')
-rw-r--r-- | cli/tools/test/mod.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index e7273c069..81dc36a89 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1611,9 +1611,16 @@ pub(crate) fn is_supported_test_path(path: &Path) -> bool { fn has_supported_test_path_name(path: &Path) -> bool { if let Some(name) = path.file_stem() { let basename = name.to_string_lossy(); - basename.ends_with("_test") + if basename.ends_with("_test") || basename.ends_with(".test") || basename == "test" + { + return true; + } + + path + .components() + .any(|seg| seg.as_os_str().to_str() == Some("__tests__")) } else { false } @@ -2077,6 +2084,18 @@ mod inner_test { assert!(is_supported_test_path(Path::new("foo/bar/test.jsx"))); assert!(is_supported_test_path(Path::new("foo/bar/test.ts"))); assert!(is_supported_test_path(Path::new("foo/bar/test.tsx"))); + assert!(is_supported_test_path(Path::new( + "foo/bar/__tests__/foo.js" + ))); + assert!(is_supported_test_path(Path::new( + "foo/bar/__tests__/foo.jsx" + ))); + assert!(is_supported_test_path(Path::new( + "foo/bar/__tests__/foo.ts" + ))); + assert!(is_supported_test_path(Path::new( + "foo/bar/__tests__/foo.tsx" + ))); assert!(!is_supported_test_path(Path::new("README.md"))); assert!(!is_supported_test_path(Path::new("lib/typescript.d.ts"))); assert!(!is_supported_test_path(Path::new("notatest.js"))); |