Skip to content

Commit fe01a44

Browse files
committed
Let test use dirs
1 parent 747425d commit fe01a44

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fwdansi = "1.1.0"
1919
termcolor = "1.4.1"
2020
libc = "0.2.175"
2121
rustyline = "17.0.1"
22+
walkdir = "2"
2223
anyhow.workspace = true
2324
tempfile.workspace = true
2425
tokio.workspace = true

cli/src/command/test.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,68 @@
1+
use std::path::PathBuf;
12
use std::process::Command;
3+
use walkdir::WalkDir;
24

35
use crate::{cli::TestArgs, shell::Shell};
46

7+
fn collect_ts_files(path: &PathBuf) -> anyhow::Result<Vec<PathBuf>> {
8+
let mut files = Vec::new();
9+
10+
if path.is_file() {
11+
if path.extension().and_then(|e| e.to_str()) == Some("ts") {
12+
files.push(path.clone());
13+
}
14+
} else if path.is_dir() {
15+
for entry in WalkDir::new(path)
16+
.follow_links(false)
17+
.into_iter()
18+
.filter_map(|e| e.ok())
19+
{
20+
let entry_path = entry.path();
21+
if entry_path.is_file() && entry_path.extension().and_then(|e| e.to_str()) == Some("ts")
22+
{
23+
files.push(entry_path.to_path_buf());
24+
}
25+
}
26+
}
27+
28+
Ok(files)
29+
}
30+
531
pub async fn test(_shell: &mut Shell, args: TestArgs) -> anyhow::Result<()> {
632
let exe_path = std::env::current_exe()?;
733

34+
let mut test_files = Vec::new();
35+
36+
if args.files.is_empty() {
37+
let default_tests_dir = PathBuf::from("tests");
38+
if default_tests_dir.exists() && default_tests_dir.is_dir() {
39+
test_files = collect_ts_files(&default_tests_dir)?;
40+
}
41+
42+
if test_files.is_empty() {
43+
anyhow::bail!("No test files found. Either create a 'tests/' directory with .ts files, or specify test files/directories as arguments.");
44+
}
45+
} else {
46+
for path in &args.files {
47+
let mut collected = collect_ts_files(path)?;
48+
test_files.append(&mut collected);
49+
}
50+
51+
if test_files.is_empty() {
52+
anyhow::bail!("No .ts test files found in the specified paths.");
53+
}
54+
}
55+
56+
test_files.sort();
57+
858
let mut cmd = Command::new("deno");
959
cmd.arg("test")
1060
.arg("--allow-ffi")
1161
.arg("--allow-env")
1262
.arg("--no-check")
1363
.env("LIB_PATH", exe_path);
1464

15-
for file in &args.files {
65+
for file in &test_files {
1666
cmd.arg(file);
1767
}
1868

0 commit comments

Comments
 (0)