From e37e5314f8c3a529070bff664767bd11ba166cff Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 13 Oct 2025 20:07:38 -0700 Subject: [PATCH] Support multiple books in the GUI tests This adds the ability to use multiple books for the GUI tests. This is helpful since some tests need special configuration, and sharing the same book can make it difficult or impossible to test different configurations. It also makes it difficult to make changes to the test_book since it can affect other tests. This works by placing the books in the tests/gui/books directory. The test runner will automatically build all the books. The gui tests can then just access the DOC_PATH with the name of the book. Books are now saved in a temp directory to make it easier to use the DOC_PATH variable, instead of being tests/gui/books/book_name/book which is a little awkward. Following commits will restructure the existing book. This is just a mechanical move. --- .gitignore | 2 +- CONTRIBUTING.md | 4 +- .../gui/books/test_book}/book.toml | 0 .../gui/books/test_book}/src/README.md | 0 .../gui/books/test_book}/src/SUMMARY.md | 0 .../books/test_book}/src/headings/README.md | 0 .../test_book}/src/headings/collapsed.md | 0 .../src/headings/current-to-bottom.md | 0 .../books/test_book}/src/headings/empty.md | 0 .../test_book}/src/headings/large-intro.md | 0 .../books/test_book}/src/headings/markup.md | 0 .../test_book}/src/headings/normal-intro.md | 0 .../books/test_book}/src/individual/README.md | 0 .../test_book}/src/individual/blockquote.md | 0 .../books/test_book}/src/individual/code.md | 0 .../test_book}/src/individual/emphasis.md | 0 .../test_book}/src/individual/heading.md | 0 .../books/test_book}/src/individual/image.md | 0 .../test_book}/src/individual/linebreak.md | 0 .../test_book}/src/individual/link_hr.md | 0 .../books/test_book}/src/individual/list.md | 0 .../test_book}/src/individual/mathjax.md | 0 .../books/test_book}/src/individual/mixed.md | 0 .../test_book}/src/individual/paragraph.md | 0 .../src/individual/strikethrough.md | 0 .../books/test_book}/src/individual/table.md | 0 .../books/test_book}/src/individual/task.md | 0 .../books/test_book}/src/languages/README.md | 0 .../test_book}/src/languages/highlight.md | 0 .../gui/books/test_book}/src/last.md | 0 .../gui/books/test_book}/src/prefix.md | 0 .../gui/books/test_book}/src/rust/README.md | 0 .../test_book}/src/rust/rust_codeblock.md | 0 .../gui/books/test_book}/src/suffix.md | 0 tests/gui/heading-nav-collapsed.goml | 2 +- tests/gui/heading-nav-current-to-bottom.goml | 2 +- tests/gui/heading-nav-empty.goml | 2 +- tests/gui/heading-nav-large-intro.goml | 2 +- tests/gui/heading-nav-markup.goml | 2 +- tests/gui/heading-nav-normal-intro.goml | 2 +- tests/gui/help.goml | 2 +- tests/gui/move-between-pages.goml | 2 +- tests/gui/redirect.goml | 54 ++++++------- tests/gui/runner.rs | 76 ++++++++++++++++--- tests/gui/search.goml | 6 +- tests/gui/sidebar-active.goml | 8 +- tests/gui/sidebar-nojs.goml | 2 +- tests/gui/sidebar.goml | 2 +- tests/gui/theme.goml | 2 +- 49 files changed, 111 insertions(+), 61 deletions(-) rename {test_book => tests/gui/books/test_book}/book.toml (100%) rename {test_book => tests/gui/books/test_book}/src/README.md (100%) rename {test_book => tests/gui/books/test_book}/src/SUMMARY.md (100%) rename {test_book => tests/gui/books/test_book}/src/headings/README.md (100%) rename {test_book => tests/gui/books/test_book}/src/headings/collapsed.md (100%) rename {test_book => tests/gui/books/test_book}/src/headings/current-to-bottom.md (100%) rename {test_book => tests/gui/books/test_book}/src/headings/empty.md (100%) rename {test_book => tests/gui/books/test_book}/src/headings/large-intro.md (100%) rename {test_book => tests/gui/books/test_book}/src/headings/markup.md (100%) rename {test_book => tests/gui/books/test_book}/src/headings/normal-intro.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/README.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/blockquote.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/code.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/emphasis.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/heading.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/image.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/linebreak.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/link_hr.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/list.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/mathjax.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/mixed.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/paragraph.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/strikethrough.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/table.md (100%) rename {test_book => tests/gui/books/test_book}/src/individual/task.md (100%) rename {test_book => tests/gui/books/test_book}/src/languages/README.md (100%) rename {test_book => tests/gui/books/test_book}/src/languages/highlight.md (100%) rename {test_book => tests/gui/books/test_book}/src/last.md (100%) rename {test_book => tests/gui/books/test_book}/src/prefix.md (100%) rename {test_book => tests/gui/books/test_book}/src/rust/README.md (100%) rename {test_book => tests/gui/books/test_book}/src/rust/rust_codeblock.md (100%) rename {test_book => tests/gui/books/test_book}/src/suffix.md (100%) diff --git a/.gitignore b/.gitignore index 1865ff97..5eacf964 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ guide/book .vscode tests/dummy_book/book/ -test_book/book/ +tests/gui/books/*/book/ tests/testsuite/*/*/book/ # Ignore Jetbrains specific files. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1fdb589d..69eb2d49 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -185,9 +185,7 @@ If you want to disable the headless mode, use the `--disable-headless-test` opti cargo test --test gui -- --disable-headless-test ``` -The GUI tests are in the directory `tests/gui` in text files with the `.goml` extension. These tests are run -using a `node.js` framework called `browser-ui-test`. You can find documentation for this language on its -[repository](https://github.com/GuillaumeGomez/browser-UI-test/blob/master/goml-script.md). +The GUI tests are in the directory `tests/gui` in text files with the `.goml` extension. The books that the tests use are located in the `tests/gui/books` directory. These tests are run using a `node.js` framework called `browser-ui-test`. You can find documentation for this language on its [repository](https://github.com/GuillaumeGomez/browser-UI-test/blob/master/goml-script.md). ### Checking changes in `.js` files diff --git a/test_book/book.toml b/tests/gui/books/test_book/book.toml similarity index 100% rename from test_book/book.toml rename to tests/gui/books/test_book/book.toml diff --git a/test_book/src/README.md b/tests/gui/books/test_book/src/README.md similarity index 100% rename from test_book/src/README.md rename to tests/gui/books/test_book/src/README.md diff --git a/test_book/src/SUMMARY.md b/tests/gui/books/test_book/src/SUMMARY.md similarity index 100% rename from test_book/src/SUMMARY.md rename to tests/gui/books/test_book/src/SUMMARY.md diff --git a/test_book/src/headings/README.md b/tests/gui/books/test_book/src/headings/README.md similarity index 100% rename from test_book/src/headings/README.md rename to tests/gui/books/test_book/src/headings/README.md diff --git a/test_book/src/headings/collapsed.md b/tests/gui/books/test_book/src/headings/collapsed.md similarity index 100% rename from test_book/src/headings/collapsed.md rename to tests/gui/books/test_book/src/headings/collapsed.md diff --git a/test_book/src/headings/current-to-bottom.md b/tests/gui/books/test_book/src/headings/current-to-bottom.md similarity index 100% rename from test_book/src/headings/current-to-bottom.md rename to tests/gui/books/test_book/src/headings/current-to-bottom.md diff --git a/test_book/src/headings/empty.md b/tests/gui/books/test_book/src/headings/empty.md similarity index 100% rename from test_book/src/headings/empty.md rename to tests/gui/books/test_book/src/headings/empty.md diff --git a/test_book/src/headings/large-intro.md b/tests/gui/books/test_book/src/headings/large-intro.md similarity index 100% rename from test_book/src/headings/large-intro.md rename to tests/gui/books/test_book/src/headings/large-intro.md diff --git a/test_book/src/headings/markup.md b/tests/gui/books/test_book/src/headings/markup.md similarity index 100% rename from test_book/src/headings/markup.md rename to tests/gui/books/test_book/src/headings/markup.md diff --git a/test_book/src/headings/normal-intro.md b/tests/gui/books/test_book/src/headings/normal-intro.md similarity index 100% rename from test_book/src/headings/normal-intro.md rename to tests/gui/books/test_book/src/headings/normal-intro.md diff --git a/test_book/src/individual/README.md b/tests/gui/books/test_book/src/individual/README.md similarity index 100% rename from test_book/src/individual/README.md rename to tests/gui/books/test_book/src/individual/README.md diff --git a/test_book/src/individual/blockquote.md b/tests/gui/books/test_book/src/individual/blockquote.md similarity index 100% rename from test_book/src/individual/blockquote.md rename to tests/gui/books/test_book/src/individual/blockquote.md diff --git a/test_book/src/individual/code.md b/tests/gui/books/test_book/src/individual/code.md similarity index 100% rename from test_book/src/individual/code.md rename to tests/gui/books/test_book/src/individual/code.md diff --git a/test_book/src/individual/emphasis.md b/tests/gui/books/test_book/src/individual/emphasis.md similarity index 100% rename from test_book/src/individual/emphasis.md rename to tests/gui/books/test_book/src/individual/emphasis.md diff --git a/test_book/src/individual/heading.md b/tests/gui/books/test_book/src/individual/heading.md similarity index 100% rename from test_book/src/individual/heading.md rename to tests/gui/books/test_book/src/individual/heading.md diff --git a/test_book/src/individual/image.md b/tests/gui/books/test_book/src/individual/image.md similarity index 100% rename from test_book/src/individual/image.md rename to tests/gui/books/test_book/src/individual/image.md diff --git a/test_book/src/individual/linebreak.md b/tests/gui/books/test_book/src/individual/linebreak.md similarity index 100% rename from test_book/src/individual/linebreak.md rename to tests/gui/books/test_book/src/individual/linebreak.md diff --git a/test_book/src/individual/link_hr.md b/tests/gui/books/test_book/src/individual/link_hr.md similarity index 100% rename from test_book/src/individual/link_hr.md rename to tests/gui/books/test_book/src/individual/link_hr.md diff --git a/test_book/src/individual/list.md b/tests/gui/books/test_book/src/individual/list.md similarity index 100% rename from test_book/src/individual/list.md rename to tests/gui/books/test_book/src/individual/list.md diff --git a/test_book/src/individual/mathjax.md b/tests/gui/books/test_book/src/individual/mathjax.md similarity index 100% rename from test_book/src/individual/mathjax.md rename to tests/gui/books/test_book/src/individual/mathjax.md diff --git a/test_book/src/individual/mixed.md b/tests/gui/books/test_book/src/individual/mixed.md similarity index 100% rename from test_book/src/individual/mixed.md rename to tests/gui/books/test_book/src/individual/mixed.md diff --git a/test_book/src/individual/paragraph.md b/tests/gui/books/test_book/src/individual/paragraph.md similarity index 100% rename from test_book/src/individual/paragraph.md rename to tests/gui/books/test_book/src/individual/paragraph.md diff --git a/test_book/src/individual/strikethrough.md b/tests/gui/books/test_book/src/individual/strikethrough.md similarity index 100% rename from test_book/src/individual/strikethrough.md rename to tests/gui/books/test_book/src/individual/strikethrough.md diff --git a/test_book/src/individual/table.md b/tests/gui/books/test_book/src/individual/table.md similarity index 100% rename from test_book/src/individual/table.md rename to tests/gui/books/test_book/src/individual/table.md diff --git a/test_book/src/individual/task.md b/tests/gui/books/test_book/src/individual/task.md similarity index 100% rename from test_book/src/individual/task.md rename to tests/gui/books/test_book/src/individual/task.md diff --git a/test_book/src/languages/README.md b/tests/gui/books/test_book/src/languages/README.md similarity index 100% rename from test_book/src/languages/README.md rename to tests/gui/books/test_book/src/languages/README.md diff --git a/test_book/src/languages/highlight.md b/tests/gui/books/test_book/src/languages/highlight.md similarity index 100% rename from test_book/src/languages/highlight.md rename to tests/gui/books/test_book/src/languages/highlight.md diff --git a/test_book/src/last.md b/tests/gui/books/test_book/src/last.md similarity index 100% rename from test_book/src/last.md rename to tests/gui/books/test_book/src/last.md diff --git a/test_book/src/prefix.md b/tests/gui/books/test_book/src/prefix.md similarity index 100% rename from test_book/src/prefix.md rename to tests/gui/books/test_book/src/prefix.md diff --git a/test_book/src/rust/README.md b/tests/gui/books/test_book/src/rust/README.md similarity index 100% rename from test_book/src/rust/README.md rename to tests/gui/books/test_book/src/rust/README.md diff --git a/test_book/src/rust/rust_codeblock.md b/tests/gui/books/test_book/src/rust/rust_codeblock.md similarity index 100% rename from test_book/src/rust/rust_codeblock.md rename to tests/gui/books/test_book/src/rust/rust_codeblock.md diff --git a/test_book/src/suffix.md b/tests/gui/books/test_book/src/suffix.md similarity index 100% rename from test_book/src/suffix.md rename to tests/gui/books/test_book/src/suffix.md diff --git a/tests/gui/heading-nav-collapsed.goml b/tests/gui/heading-nav-collapsed.goml index 66c2bff2..2eabf0ab 100644 --- a/tests/gui/heading-nav-collapsed.goml +++ b/tests/gui/heading-nav-collapsed.goml @@ -1,7 +1,7 @@ // Tests for collapsed heading sidebar navigation. set-window-size: (1400, 800) -go-to: |DOC_PATH| + "headings/collapsed.html" +go-to: |DOC_PATH| + "test_book/headings/collapsed.html" assert-count: (".header-item", 12) assert-count: (".current-header", 1) diff --git a/tests/gui/heading-nav-current-to-bottom.goml b/tests/gui/heading-nav-current-to-bottom.goml index 9375fcbe..8bc8a238 100644 --- a/tests/gui/heading-nav-current-to-bottom.goml +++ b/tests/gui/heading-nav-current-to-bottom.goml @@ -2,7 +2,7 @@ // bottom. set-window-size: (1400, 800) -go-to: |DOC_PATH| + "headings/current-to-bottom.html" +go-to: |DOC_PATH| + "test_book/headings/current-to-bottom.html" assert-count: (".current-header", 1) assert-text: (".current-header", "First header") diff --git a/tests/gui/heading-nav-empty.goml b/tests/gui/heading-nav-empty.goml index af7de2b7..c86df73a 100644 --- a/tests/gui/heading-nav-empty.goml +++ b/tests/gui/heading-nav-empty.goml @@ -1,6 +1,6 @@ // When there aren't any headings, there shouldn't be any header items in the sidebar. set-window-size: (1400, 800) -go-to: |DOC_PATH| + "headings/empty.html" +go-to: |DOC_PATH| + "test_book/headings/empty.html" assert-count: (".header-item", 0) assert-count: (".current-header", 0) diff --git a/tests/gui/heading-nav-large-intro.goml b/tests/gui/heading-nav-large-intro.goml index a590d1bc..b9c78aa0 100644 --- a/tests/gui/heading-nav-large-intro.goml +++ b/tests/gui/heading-nav-large-intro.goml @@ -2,7 +2,7 @@ // you scroll down and make it visible on screen. set-window-size: (1400, 800) -go-to: |DOC_PATH| + "headings/large-intro.html" +go-to: |DOC_PATH| + "test_book/headings/large-intro.html" assert-count: (".header-item", 2) assert-count: (".current-header", 0) diff --git a/tests/gui/heading-nav-markup.goml b/tests/gui/heading-nav-markup.goml index e6b37f17..ad4b5e20 100644 --- a/tests/gui/heading-nav-markup.goml +++ b/tests/gui/heading-nav-markup.goml @@ -1,7 +1,7 @@ // When a header has various markup, the sidebar should replicate it. set-window-size: (1400, 800) -go-to: |DOC_PATH| + "headings/markup.html" +go-to: |DOC_PATH| + "test_book/headings/markup.html" assert-count: (".header-item", 5) assert-count: (".current-header", 1) diff --git a/tests/gui/heading-nav-normal-intro.goml b/tests/gui/heading-nav-normal-intro.goml index c8d14a37..f06d4eab 100644 --- a/tests/gui/heading-nav-normal-intro.goml +++ b/tests/gui/heading-nav-normal-intro.goml @@ -2,7 +2,7 @@ // should be "current". set-window-size: (1400, 800) -go-to: |DOC_PATH| + "headings/normal-intro.html" +go-to: |DOC_PATH| + "test_book/headings/normal-intro.html" assert-count: (".header-item", 4) assert-count: (".current-header", 1) assert-text: (".current-header", "The first heading") diff --git a/tests/gui/help.goml b/tests/gui/help.goml index c22eda02..99e3d6ba 100644 --- a/tests/gui/help.goml +++ b/tests/gui/help.goml @@ -1,6 +1,6 @@ // This GUI test checks help popup. -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" assert-css: ("#mdbook-help-container", {"display": "none"}) press-key: '?' wait-for-css: ("#mdbook-help-container", {"display": "flex"}) diff --git a/tests/gui/move-between-pages.goml b/tests/gui/move-between-pages.goml index ec71487f..93a4b9cc 100644 --- a/tests/gui/move-between-pages.goml +++ b/tests/gui/move-between-pages.goml @@ -1,6 +1,6 @@ // This tests pressing the left and right arrows moving to previous and next page. -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" // default page is the first numbered page assert-text: ("title", "Introduction - mdBook test book") diff --git a/tests/gui/redirect.goml b/tests/gui/redirect.goml index 968f94ba..e11e7279 100644 --- a/tests/gui/redirect.goml +++ b/tests/gui/redirect.goml @@ -1,41 +1,41 @@ -go-to: |DOC_PATH| + "format/config.html" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html"}) +go-to: |DOC_PATH| + "test_book/format/config.html" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html"}) // Check that it preserves fragments when redirecting. -go-to: |DOC_PATH| + "format/config.html#fragment" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html#fragment"}) +go-to: |DOC_PATH| + "test_book/format/config.html#fragment" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html#fragment"}) // The fragment one here isn't necessary, but should still work. -go-to: |DOC_PATH| + "pointless-fragment.html" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html"}) -go-to: |DOC_PATH| + "pointless-fragment.html#foo" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html#foo"}) +go-to: |DOC_PATH| + "test_book/pointless-fragment.html" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html"}) +go-to: |DOC_PATH| + "test_book/pointless-fragment.html#foo" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html#foo"}) // Page rename, and a fragment rename. -go-to: |DOC_PATH| + "rename-page-and-fragment.html" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html"}) -go-to: |DOC_PATH| + "rename-page-and-fragment.html#orig" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html#new"}) +go-to: |DOC_PATH| + "test_book/rename-page-and-fragment.html" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html"}) +go-to: |DOC_PATH| + "test_book/rename-page-and-fragment.html#orig" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html#new"}) // Page rename, and the fragment goes to a *different* page from the default. -go-to: |DOC_PATH| + "rename-page-fragment-elsewhere.html" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html"}) -go-to: |DOC_PATH| + "rename-page-fragment-elsewhere.html#orig" -assert-window-property: ({"location": |DOC_PATH| + "suffix.html#new"}) +go-to: |DOC_PATH| + "test_book/rename-page-fragment-elsewhere.html" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html"}) +go-to: |DOC_PATH| + "test_book/rename-page-fragment-elsewhere.html#orig" +assert-window-property: ({"location": |DOC_PATH| + "test_book/suffix.html#new"}) // Rename fragment on an existing page. -go-to: |DOC_PATH| + "prefix.html#orig" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html#new"}) +go-to: |DOC_PATH| + "test_book/prefix.html#orig" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html#new"}) // Other fragments aren't affected. -go-to: |DOC_PATH| + "index.html" // Reset page since redirects are processed on load. -go-to: |DOC_PATH| + "prefix.html" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html"}) -go-to: |DOC_PATH| + "index.html" // Reset page since redirects are processed on load. -go-to: |DOC_PATH| + "prefix.html#dont-change" -assert-window-property: ({"location": |DOC_PATH| + "prefix.html#dont-change"}) +go-to: |DOC_PATH| + "test_book/index.html" // Reset page since redirects are processed on load. +go-to: |DOC_PATH| + "test_book/prefix.html" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html"}) +go-to: |DOC_PATH| + "test_book/index.html" // Reset page since redirects are processed on load. +go-to: |DOC_PATH| + "test_book/prefix.html#dont-change" +assert-window-property: ({"location": |DOC_PATH| + "test_book/prefix.html#dont-change"}) // Rename fragment on an existing page to another page. -go-to: |DOC_PATH| + "index.html" // Reset page since redirects are processed on load. -go-to: |DOC_PATH| + "prefix.html#orig-new-page" -assert-window-property: ({"location": |DOC_PATH| + "suffix.html#new"}) +go-to: |DOC_PATH| + "test_book/index.html" // Reset page since redirects are processed on load. +go-to: |DOC_PATH| + "test_book/prefix.html#orig-new-page" +assert-window-property: ({"location": |DOC_PATH| + "test_book/suffix.html#new"}) diff --git a/tests/gui/runner.rs b/tests/gui/runner.rs index 8bae07a6..adecbd3c 100644 --- a/tests/gui/runner.rs +++ b/tests/gui/runner.rs @@ -5,9 +5,9 @@ //! information. use serde_json::Value; -use std::env::current_dir; -use std::fs::{read_to_string, remove_dir_all}; -use std::process::Command; +use std::fs::read_to_string; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; fn get_available_browser_ui_test_version_inner(global: bool) -> Option { let mut command = Command::new("npm"); @@ -69,23 +69,75 @@ fn main() { } } - let current_dir = current_dir().expect("failed to retrieve current directory"); - let test_book = current_dir.join("test_book"); + let out_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("gui"); + build_books(&out_dir); + run_browser_ui_test(&out_dir); +} - // Result doesn't matter. - let _ = remove_dir_all(test_book.join("book")); +fn build_books(out_dir: &Path) { + let exe = build_mdbook(); + let root = Path::new(env!("CARGO_MANIFEST_DIR")); + let books_dir = root.join("tests/gui/books"); + for entry in books_dir.read_dir().unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + if !path.is_dir() { + continue; + } + println!("Building `{}`", path.display()); + let mut cmd = Command::new(&exe); + let output = cmd + .arg("build") + .arg("--dest-dir") + .arg(out_dir.join(path.file_name().unwrap())) + .arg(&path) + .output() + .expect("mdbook should be built"); + check_status(&cmd, &output); + } +} +fn build_mdbook() -> PathBuf { let mut cmd = Command::new("cargo"); - cmd.arg("run").arg("build").arg(&test_book); - // Then we run the GUI tests on it. - assert!(cmd.status().is_ok_and(|status| status.success())); + let output = cmd + .arg("build") + .output() + .expect("cargo should be installed"); + check_status(&cmd, &output); + let target_dir = detect_target_dir(); + target_dir.join("debug/mdbook") +} - let book_dir = format!("file://{}", current_dir.join("test_book/book/").display()); +fn detect_target_dir() -> PathBuf { + let mut cmd = Command::new("cargo"); + let output = cmd + .args(["metadata", "--format-version=1", "--no-deps"]) + .output() + .expect("cargo should be installed"); + check_status(&cmd, &output); + let v: serde_json::Value = serde_json::from_slice(&output.stdout).expect("invalid json"); + PathBuf::from(v["target_directory"].as_str().unwrap()) +} +fn check_status(cmd: &Command, output: &Output) { + if !output.status.success() { + eprintln!("error: `{cmd:?}` failed"); + let stdout = std::str::from_utf8(&output.stdout).expect("stdout is not utf8"); + let stderr = std::str::from_utf8(&output.stderr).expect("stderr is not utf8"); + eprintln!("\n--- stdout\n{stdout}\n--- stderr\n{stderr}"); + std::process::exit(1); + } +} + +fn run_browser_ui_test(out_dir: &Path) { let mut command = Command::new("npx"); + let mut doc_path = format!("file://{}", out_dir.display()); + if !doc_path.ends_with('/') { + doc_path.push('/'); + } command .arg("browser-ui-test") - .args(["--variable", "DOC_PATH", book_dir.as_str()]) + .args(["--variable", "DOC_PATH", doc_path.as_str()]) .args(["--display-format", "compact"]); for arg in std::env::args().skip(1) { diff --git a/tests/gui/search.goml b/tests/gui/search.goml index 145bbd1e..c2bf4f93 100644 --- a/tests/gui/search.goml +++ b/tests/gui/search.goml @@ -1,7 +1,7 @@ // This tests basic search behavior. fail-on-js-error: true -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" define-function: ( "open-search", @@ -31,7 +31,7 @@ write: "strikethrough" wait-for-text: ("#mdbook-searchresults-header", "2 search results for 'strikethrough':") // Now we test search shortcuts and more page changes. -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" // This check is to ensure that the search bar is inside the search wrapper. assert: "#mdbook-search-wrapper #mdbook-searchbar" @@ -66,7 +66,7 @@ assert-document-property: ({"URL": "?search=test"}, ENDS_WITH) // Now we ensure that when we land on the page with a "search in progress", the search results are // loaded and that the search input has focus. -go-to: |DOC_PATH| + "index.html?search=test" +go-to: |DOC_PATH| + "test_book/index.html?search=test" wait-for-text: ("#mdbook-searchresults-header", "search results for 'test':", ENDS_WITH) assert: "#mdbook-searchbar:focus" assert: "#mdbook-searchresults" diff --git a/tests/gui/sidebar-active.goml b/tests/gui/sidebar-active.goml index a029b2d2..8f01a878 100644 --- a/tests/gui/sidebar-active.goml +++ b/tests/gui/sidebar-active.goml @@ -1,17 +1,17 @@ // This GUI test checks the active page sidebar highlight. -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" assert-text: ("mdbook-sidebar-scrollbox a.active", "Prefix Chapter") -go-to: |DOC_PATH| + "individual/index.html" +go-to: |DOC_PATH| + "test_book/individual/index.html" assert-text: ("mdbook-sidebar-scrollbox a.active", "3. Markdown Individual tags") -go-to: |DOC_PATH| + "index.html?highlight=test" +go-to: |DOC_PATH| + "test_book/index.html?highlight=test" assert-text: ("mdbook-sidebar-scrollbox a.active", "Prefix Chapter") -go-to: |DOC_PATH| + "individual/index.html?highlight=test" +go-to: |DOC_PATH| + "test_book/individual/index.html?highlight=test" assert-text: ("mdbook-sidebar-scrollbox a.active", "3. Markdown Individual tags") diff --git a/tests/gui/sidebar-nojs.goml b/tests/gui/sidebar-nojs.goml index 9867b0a8..e153a550 100644 --- a/tests/gui/sidebar-nojs.goml +++ b/tests/gui/sidebar-nojs.goml @@ -4,7 +4,7 @@ // We disable javascript javascript: false -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" store-value: (height, 1028) set-window-size: (1028, |height|) diff --git a/tests/gui/sidebar.goml b/tests/gui/sidebar.goml index ec44f5a4..663b84f2 100644 --- a/tests/gui/sidebar.goml +++ b/tests/gui/sidebar.goml @@ -1,7 +1,7 @@ // This GUI test checks sidebar hide/show and also its behaviour on smaller // width. -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" set-window-size: (1100, 600) // Need to reload for the new size to be taken account by the JS. reload: diff --git a/tests/gui/theme.goml b/tests/gui/theme.goml index 33fde6f0..683e69a9 100644 --- a/tests/gui/theme.goml +++ b/tests/gui/theme.goml @@ -2,7 +2,7 @@ debug: true -go-to: |DOC_PATH| + "index.html" +go-to: |DOC_PATH| + "test_book/index.html" // TODO: Dark mode is automatic, how to check that here? assert-css: ("#mdbook-theme-list", {"display": "none"})