Skip to content

Commit 4b266f1

Browse files
authored
Merge pull request #2590 from GuillaumeGomez/filter-gui-tests
Allow to run only some specific GUI tests
2 parents 07b25cd + fc7ef59 commit 4b266f1

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

CONTRIBUTING.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,15 @@ GUI tests are checked with the GUI testsuite. To run it, you need to install `np
144144
cargo test --test gui
145145
```
146146
147+
If you want to only run some tests, you can filter them by passing (part of) their name:
148+
149+
```
150+
cargo test --test gui -- search
151+
```
152+
147153
The first time, it'll fail and ask you to install the `browser-ui-test` package. Install it then re-run the tests.
148154
149-
If you want to disable the headless mode, use the `DISABLE_HEADLESS_TEST=1` environment variable:
155+
If you want to disable the headless mode, use the `--disable-headless-test` option:
150156
151157
```
152158
cargo test --test gui -- --disable-headless-test

tests/gui/runner.rs

+48-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use std::collections::HashSet;
12
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};
34
use std::process::Command;
45

56
fn get_available_browser_ui_test_version_inner(global: bool) -> Option<String> {
@@ -72,15 +73,58 @@ fn main() {
7273

7374
let book_dir = format!("file://{}", current_dir.join("test_book/book/").display());
7475

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+
7586
let mut command = Command::new("npx");
7687
command
7788
.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 {
8191
command.arg("--no-headless");
8292
}
8393

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+
84128
// Then we run the GUI tests on it.
85129
let status = command.status().expect("failed to get command output");
86130
assert!(status.success(), "{status:?}");

0 commit comments

Comments
 (0)