Skip to content

Commit 7c8e234

Browse files
branchseerclaude
andcommitted
feat(tests): add CLI filter argument for snapshot tests
Allow filtering fixtures by name substring when running tests: - `cargo test -p vite_task_bin --test e2e_snapshots -- stdin` - `cargo test -p vite_task_plan --test plan_snapshots -- cache` Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d4a119f commit 7c8e234

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

  • crates
    • vite_task_bin/tests/e2e_snapshots
    • vite_task_plan/tests/plan_snapshots

crates/vite_task_bin/tests/e2e_snapshots/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ struct SnapshotsFile {
5252
pub e2e_cases: Vec<E2e>,
5353
}
5454

55-
fn run_case(tmpdir: &AbsolutePath, fixture_path: &Path) {
55+
fn run_case(tmpdir: &AbsolutePath, fixture_path: &Path, filter: Option<&str>) {
5656
let fixture_name = fixture_path.file_name().unwrap().to_str().unwrap();
5757
if fixture_name.starts_with(".") {
5858
return; // skip hidden files like .DS_Store
5959
}
6060

61+
// Skip if filter doesn't match
62+
if let Some(f) = filter {
63+
if !fixture_name.contains(f) {
64+
return;
65+
}
66+
}
67+
6168
// Configure insta to write snapshots to fixture directory
6269
let mut settings = insta::Settings::clone_current();
6370
settings.set_snapshot_path(fixture_path.join("snapshots"));
@@ -168,13 +175,16 @@ fn run_case_inner(tmpdir: &AbsolutePath, fixture_path: &Path, fixture_name: &str
168175
}
169176

170177
fn main() {
178+
let filter = std::env::args().nth(1);
179+
171180
let tmp_dir = tempfile::tempdir().unwrap();
172181
let tmp_dir_path = AbsolutePathBuf::new(tmp_dir.path().canonicalize().unwrap()).unwrap();
173182

174183
let tests_dir = std::env::current_dir().unwrap().join("tests");
175184

176185
insta::glob!(tests_dir, "e2e_snapshots/fixtures/*", |case_path| run_case(
177186
&tmp_dir_path,
178-
case_path
187+
case_path,
188+
filter.as_deref()
179189
));
180190
}

crates/vite_task_plan/tests/plan_snapshots/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@ struct SnapshotsFile {
2525
pub plan_cases: Vec<Plan>,
2626
}
2727

28-
fn run_case(runtime: &Runtime, tmpdir: &AbsolutePath, fixture_path: &Path) {
28+
fn run_case(runtime: &Runtime, tmpdir: &AbsolutePath, fixture_path: &Path, filter: Option<&str>) {
2929
let fixture_name = fixture_path.file_name().unwrap().to_str().unwrap();
3030
if fixture_name.starts_with(".") {
3131
return; // skip hidden files like .DS_Store
3232
}
3333

34+
// Skip if filter doesn't match
35+
if let Some(f) = filter {
36+
if !fixture_name.contains(f) {
37+
return;
38+
}
39+
}
40+
3441
// Configure insta to write snapshots to fixture directory
3542
let mut settings = insta::Settings::clone_current();
3643
settings.set_snapshot_path(fixture_path.join("snapshots"));
@@ -135,6 +142,8 @@ fn run_case_inner(
135142
}
136143

137144
fn main() {
145+
let filter = std::env::args().nth(1);
146+
138147
let tokio_runtime = Runtime::new().unwrap();
139148
let tmp_dir = tempfile::tempdir().unwrap();
140149
let tmp_dir_path = AbsolutePathBuf::new(tmp_dir.path().canonicalize().unwrap()).unwrap();
@@ -144,6 +153,7 @@ fn main() {
144153
insta::glob!(tests_dir, "plan_snapshots/fixtures/*", |case_path| run_case(
145154
&tokio_runtime,
146155
&tmp_dir_path,
147-
case_path
156+
case_path,
157+
filter.as_deref()
148158
));
149159
}

0 commit comments

Comments
 (0)