rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
18.42k stars 1.65k forks source link

Add base for GUI tests #2476

Open GuillaumeGomez opened 2 weeks ago

GuillaumeGomez commented 2 weeks ago

As discussed with @ehuss, this PR adds the basics for adding more GUI tests. Just add more .goml files in the tests/gui folder.

This is the same GUI test framework used in rustdoc and docs.rs.

If you need any explanation on how it works, or if you have any question, please don't hesitate to ask.

GuillaumeGomez commented 2 weeks ago

Finally fixed windows build. :')

notriddle commented 6 days ago

I think we should not use the default test harness for this. We can lean on Cargo a lot more instead of using environment variables:

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 984e19222..1f9c84522 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -58,11 +58,9 @@ jobs:
     - name: Install browser-ui-test
       if: matrix.os != 'windows-latest'
       run: npm install browser-ui-test@"${BROWSER_UI_TEST_VERSION}"
-    - name: Build and run tests (+ GUI)
+    - name: Build and run GUI tests
       if: matrix.os != 'windows-latest'
-      env:
-        GUI_TESTS: 1
-      run: cargo test --locked --target ${{ matrix.target }}
+      run: cargo test --locked --target ${{ matrix.target }} --test gui
     - name: Build and run tests
       if: matrix.os == 'windows-latest'
       run: cargo test --locked --target ${{ matrix.target }}
diff --git a/Cargo.toml b/Cargo.toml
index 5d593b270..3d3704390 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -82,3 +82,10 @@ name = "remove-emphasis"
 path = "examples/remove-emphasis/test.rs"
 crate-type = ["lib"]
 test = true
+
+[[test]]
+harness = false
+test = false
+name = "gui"
+path = "tests/gui/runner.rs"
+crate-type = ["bin"]
diff --git a/tests/gui.rs b/tests/gui/runner.rs
similarity index 93%
rename from tests/gui.rs
rename to tests/gui/runner.rs
index 92d9df319..0ec7f5456 100644
--- a/tests/gui.rs
+++ b/tests/gui/runner.rs
@@ -38,12 +38,7 @@ fn expected_browser_ui_test_version() -> String {
     panic!("failed to retrieved `browser-ui-test` version");
 }

-#[test]
-fn gui() {
-    if !std::env::var("GUI_TESTS").is_ok_and(|value| value == "1") {
-        eprintln!("Skipping GUI tests. To enable them, add the GUI_TESTS=1 environment variable.");
-        return;
-    }
+fn main() {
     let browser_ui_test_version = expected_browser_ui_test_version();
     match get_available_browser_ui_test_version() {
         Some(version) => {
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index dcbb9dbb4..347f3a04f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -141,7 +141,7 @@ If possible, do your best to avoid breaking older browser releases.
 GUI tests are checked with the GUI testsuite. To run it, you need to install `npm` first. Then run:

-GUI_TESTS=1 cargo test gui +cargo test --test gui


 The first time, it'll fail and ask you to install the `browser-ui-test` package. Install it then re-run the tests.
GuillaumeGomez commented 3 days ago

Great idea, thanks! Updated.