|
| 1 | +use std::collections::HashSet; |
1 | 2 | use std::env::current_dir;
|
2 |
| -use std::fs::{read_to_string, remove_dir_all}; |
| 3 | +use std::fs::{read_dir, read_to_string, remove_dir_all}; |
3 | 4 | use std::process::Command;
|
4 | 5 |
|
5 | 6 | fn get_available_browser_ui_test_version_inner(global: bool) -> Option<String> {
|
@@ -72,15 +73,58 @@ fn main() {
|
72 | 73 |
|
73 | 74 | let book_dir = format!("file://{}", current_dir.join("test_book/book/").display());
|
74 | 75 |
|
| 76 | + let mut no_headless = false; |
| 77 | + let mut filters = Vec::new(); |
| 78 | + for arg in std::env::args() { |
| 79 | + if arg == "--disable-headless-test" { |
| 80 | + no_headless = true; |
| 81 | + } else { |
| 82 | + filters.push(arg); |
| 83 | + } |
| 84 | + } |
| 85 | + |
75 | 86 | let mut command = Command::new("npx");
|
76 | 87 | command
|
77 | 88 | .arg("browser-ui-test")
|
78 |
| - .args(["--variable", "DOC_PATH", book_dir.as_str()]) |
79 |
| - .args(["--test-folder", "tests/gui"]); |
80 |
| - if std::env::args().any(|arg| arg == "--disable-headless-test") { |
| 89 | + .args(["--variable", "DOC_PATH", book_dir.as_str()]); |
| 90 | + if no_headless { |
81 | 91 | command.arg("--no-headless");
|
82 | 92 | }
|
83 | 93 |
|
| 94 | + let test_dir = "tests/gui"; |
| 95 | + if filters.is_empty() { |
| 96 | + command.args(["--test-folder", test_dir]); |
| 97 | + } else { |
| 98 | + let files = read_dir(test_dir) |
| 99 | + .map(|dir| { |
| 100 | + dir.filter_map(|entry| entry.ok()) |
| 101 | + .map(|entry| entry.path()) |
| 102 | + .filter(|path| { |
| 103 | + path.extension().is_some_and(|ext| ext == "goml") && path.is_file() |
| 104 | + }) |
| 105 | + .collect::<Vec<_>>() |
| 106 | + }) |
| 107 | + .unwrap_or(Vec::new()); |
| 108 | + let mut matches = HashSet::new(); |
| 109 | + for filter in filters { |
| 110 | + for file in files.iter().filter(|f| { |
| 111 | + f.file_name() |
| 112 | + .and_then(|name| name.to_str()) |
| 113 | + .is_some_and(|name| name.contains(&filter)) |
| 114 | + }) { |
| 115 | + matches.insert(file.display().to_string()); |
| 116 | + } |
| 117 | + } |
| 118 | + if matches.is_empty() { |
| 119 | + println!("No test found"); |
| 120 | + return; |
| 121 | + } |
| 122 | + command.arg("--test-files"); |
| 123 | + for entry in matches { |
| 124 | + command.arg(entry); |
| 125 | + } |
| 126 | + } |
| 127 | + |
84 | 128 | // Then we run the GUI tests on it.
|
85 | 129 | let status = command.status().expect("failed to get command output");
|
86 | 130 | assert!(status.success(), "{status:?}");
|
|
0 commit comments