Skip to main content

browser_test/
error.rs

1/// Error contexts reported by browser-test runner operations.
2#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
3pub enum BrowserTestError {
4    /// Chromedriver could not be started.
5    #[error("Failed to start webdriver.")]
6    StartWebdriver,
7
8    /// A browser test failed while running in its `WebDriver` session.
9    #[error("Browser test '{test_name}' failed.")]
10    RunTest {
11        /// The test name reported by [`crate::BrowserTest::name`].
12        test_name: String,
13    },
14
15    /// A browser test panicked while running in its `WebDriver` session.
16    #[error("Browser test '{test_name}' panicked: {message}")]
17    Panic {
18        /// The test name reported by [`crate::BrowserTest::name`].
19        test_name: String,
20        /// A string representation of the panic payload.
21        message: String,
22    },
23
24    /// Multiple browser tests failed or panicked and were collected into one report.
25    #[error("One or more browser tests failed or panicked ({failed_tests} failed).")]
26    RunTests {
27        /// Number of failed or panicked tests collected as child reports.
28        failed_tests: usize,
29    },
30
31    /// Chromedriver could not be terminated cleanly.
32    #[error("Failed to terminate chromedriver.")]
33    TerminateWebdriver,
34
35    /// The pause prompt could not be flushed to stdout.
36    #[error("Failed to flush pause prompt.")]
37    FlushPausePrompt,
38
39    /// The pause response could not be read from stdin.
40    #[error("Failed to read pause response from stdin.")]
41    ReadPauseResponse,
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47    use assertr::prelude::*;
48
49    #[test]
50    fn run_test_error_displays_plain_test_name() {
51        let err = BrowserTestError::RunTest {
52            test_name: "login".to_owned(),
53        };
54
55        assert_that!(err.to_string()).is_equal_to("Browser test 'login' failed.");
56    }
57
58    #[test]
59    fn run_tests_error_displays_failure_count() {
60        let err = BrowserTestError::RunTests { failed_tests: 2 };
61
62        assert_that!(err.to_string())
63            .is_equal_to("One or more browser tests failed or panicked (2 failed).");
64    }
65
66    #[test]
67    fn panic_error_displays_test_name_and_message() {
68        let err = BrowserTestError::Panic {
69            test_name: "login".to_owned(),
70            message: "assertion failed".to_owned(),
71        };
72
73        assert_that!(err.to_string())
74            .is_equal_to("Browser test 'login' panicked: assertion failed");
75    }
76}