Merge pull request #2828 from GuillaumeGomez/simplify-gui

Simplify GUI tests runner
This commit is contained in:
Eric Huss 2025-09-08 17:35:25 +00:00 committed by GitHub
commit 787882069e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 38 deletions

View file

@ -1,6 +1,6 @@
{ {
"dependencies": { "dependencies": {
"browser-ui-test": "0.21.3", "browser-ui-test": "0.22.1",
"eslint": "^9.34.0" "eslint": "^9.34.0"
}, },
"scripts": { "scripts": {

View file

@ -5,9 +5,8 @@
//! information. //! information.
use serde_json::Value; use serde_json::Value;
use std::collections::HashSet;
use std::env::current_dir; use std::env::current_dir;
use std::fs::{read_dir, read_to_string, remove_dir_all}; use std::fs::{read_to_string, remove_dir_all};
use std::process::Command; use std::process::Command;
fn get_available_browser_ui_test_version_inner(global: bool) -> Option<String> { fn get_available_browser_ui_test_version_inner(global: bool) -> Option<String> {
@ -86,52 +85,21 @@ fn main() {
let mut command = Command::new("npx"); let mut command = Command::new("npx");
command command
.arg("browser-ui-test") .arg("browser-ui-test")
.args(["--variable", "DOC_PATH", book_dir.as_str()]); .args(["--variable", "DOC_PATH", book_dir.as_str()])
.args(["--display-format", "compact"]);
let mut filters = Vec::new();
for arg in std::env::args().skip(1) { for arg in std::env::args().skip(1) {
if arg == "--disable-headless-test" { if arg == "--disable-headless-test" {
command.arg("--no-headless"); command.arg("--no-headless");
} else if arg.starts_with("--") { } else if arg.starts_with("--") {
command.arg(arg); command.arg(arg);
} else { } else {
filters.push(arg); command.args(["--filter", arg.as_str()]);
} }
} }
let test_dir = "tests/gui"; let test_dir = "tests/gui";
if filters.is_empty() { command.args(["--test-folder", test_dir]);
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. // Then we run the GUI tests on it.
let status = command.status().expect("failed to get command output"); let status = command.status().expect("failed to get command output");