From fc7ef59dee00d0af6b675bc4c0aba74acc71450a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 10 Mar 2025 13:31:40 +0100 Subject: [PATCH] Allow to run only some specific GUI tests --- CONTRIBUTING.md | 8 ++++++- tests/gui/runner.rs | 52 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 293eb6e8..60e17ea1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/tests/gui/runner.rs b/tests/gui/runner.rs index ff808a72..2f9d5eb1 100644 --- a/tests/gui/runner.rs +++ b/tests/gui/runner.rs @@ -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 { @@ -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::>() + }) + .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:?}");