Allow to run only some specific GUI tests

This commit is contained in:
Guillaume Gomez
2025-03-10 13:31:40 +01:00
parent 07b25cdb64
commit fc7ef59dee
2 changed files with 55 additions and 5 deletions

View File

@@ -144,9 +144,15 @@ GUI tests are checked with the GUI testsuite. To run it, you need to install `np
cargo test --test gui
```
If you want to only run some tests, you can filter them by passing (part of) their name:
```
cargo test --test gui -- search
```
The first time, it'll fail and ask you to install the `browser-ui-test` package. Install it then re-run the tests.
If you want to disable the headless mode, use the `DISABLE_HEADLESS_TEST=1` environment variable:
If you want to disable the headless mode, use the `--disable-headless-test` option:
```
cargo test --test gui -- --disable-headless-test

View File

@@ -1,5 +1,6 @@
use std::collections::HashSet;
use std::env::current_dir;
use std::fs::{read_to_string, remove_dir_all};
use std::fs::{read_dir, read_to_string, remove_dir_all};
use std::process::Command;
fn get_available_browser_ui_test_version_inner(global: bool) -> Option<String> {
@@ -72,15 +73,58 @@ fn main() {
let book_dir = format!("file://{}", current_dir.join("test_book/book/").display());
let mut no_headless = false;
let mut filters = Vec::new();
for arg in std::env::args() {
if arg == "--disable-headless-test" {
no_headless = true;
} else {
filters.push(arg);
}
}
let mut command = Command::new("npx");
command
.arg("browser-ui-test")
.args(["--variable", "DOC_PATH", book_dir.as_str()])
.args(["--test-folder", "tests/gui"]);
if std::env::args().any(|arg| arg == "--disable-headless-test") {
.args(["--variable", "DOC_PATH", book_dir.as_str()]);
if no_headless {
command.arg("--no-headless");
}
let test_dir = "tests/gui";
if filters.is_empty() {
command.args(["--test-folder", test_dir]);
} else {
let files = read_dir(test_dir)
.map(|dir| {
dir.filter_map(|entry| entry.ok())
.map(|entry| entry.path())
.filter(|path| {
path.extension().is_some_and(|ext| ext == "goml") && path.is_file()
})
.collect::<Vec<_>>()
})
.unwrap_or(Vec::new());
let mut matches = HashSet::new();
for filter in filters {
for file in files.iter().filter(|f| {
f.file_name()
.and_then(|name| name.to_str())
.is_some_and(|name| name.contains(&filter))
}) {
matches.insert(file.display().to_string());
}
}
if matches.is_empty() {
println!("No test found");
return;
}
command.arg("--test-files");
for entry in matches {
command.arg(entry);
}
}
// Then we run the GUI tests on it.
let status = command.status().expect("failed to get command output");
assert!(status.success(), "{status:?}");