diff --git a/bonnie.toml b/bonnie.toml index 7a28e43493..106c94d67f 100644 --- a/bonnie.toml +++ b/bonnie.toml @@ -154,17 +154,23 @@ ci-prep.desc = "creates empty directories to preserve the file structure that te test.cmd = [ "cargo test", # This will ignore Wasm tests # Run tests for each example - "bonnie test single basic --headless", - "bonnie test single i18n --headless", - "bonnie test single plugins --headless", - "bonnie test single showcase --headless" + "bonnie test example core basic --headless", + "bonnie test example core unreactive --headless", + "bonnie test example core i18n --headless", + "bonnie test example core plugins --headless", + "bonnie test example core state_generation --headless", + "bonnie test example core freezing_and_thawing --headless", + "bonnie test example core global_state --headless", + "bonnie test example core idb_freezing --headless", + "bonnie test example core router_state --headless", + "bonnie test example core rx_state --headless" ] test.desc = "runs all tests headlessly (assumes geckodriver running in background)" test.subcommands.core.cmd = "cargo test" test.subcommands.core.desc = "runs cargo tests only" -test.subcommands.single.cmd = "bash ./test.sh %test %%" # A script can do backgrounding properly -test.subcommands.single.args = [ "test" ] -test.subcommands.single.desc = "tests a single tests (assumes geckodriver running in background), use `--headless` to run headlessly" +test.subcommands.example.cmd = "bash ./test.sh %category %example %%" # A script can do backgrounding properly +test.subcommands.example.args = [ "category", "example" ] +test.subcommands.example.desc = "tests a single example (assumes geckodriver running in background), use `--headless` to run headlessly" # Releases the project (maintainers only) # We commit all staged files so we can manually bump the Cargo version diff --git a/examples/core/state_generation/Cargo.toml b/examples/core/state_generation/Cargo.toml index 31e2f78370..013a6eaa56 100644 --- a/examples/core/state_generation/Cargo.toml +++ b/examples/core/state_generation/Cargo.toml @@ -10,3 +10,7 @@ perseus = { path = "../../../packages/perseus", features = [ "hydrate" ] } sycamore = "0.7" serde = { version = "1", features = ["derive"] } serde_json = "1" + +[dev-dependencies] +fantoccini = "0.17" +tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] } diff --git a/examples/core/unreactive/Cargo.toml b/examples/core/unreactive/Cargo.toml index a125929e2b..8bf83faa1b 100644 --- a/examples/core/unreactive/Cargo.toml +++ b/examples/core/unreactive/Cargo.toml @@ -10,3 +10,7 @@ perseus = { path = "../../../packages/perseus", features = [ "hydrate" ] } sycamore = "0.7" serde = { version = "1", features = ["derive"] } serde_json = "1" + +[dev-dependencies] +fantoccini = "0.17" +tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] } diff --git a/examples/core/unreactive/tests/main.rs b/examples/core/unreactive/tests/main.rs new file mode 100644 index 0000000000..7029e4c2b2 --- /dev/null +++ b/examples/core/unreactive/tests/main.rs @@ -0,0 +1,36 @@ +use fantoccini::{Client, Locator}; +use perseus::wait_for_checkpoint; + +#[perseus::test] +async fn main(c: &mut Client) -> Result<(), fantoccini::error::CmdError> { + c.goto("http://localhost:8080").await?; + wait_for_checkpoint!("begin", 0, c); + let url = c.current_url().await?; + assert!(url.as_ref().starts_with("http://localhost:8080")); + + // The greeting was passed through using build state + wait_for_checkpoint!("initial_state_present", 0, c); + wait_for_checkpoint!("page_visible", 0, c); + let greeting = c.find(Locator::Css("p")).await?.text().await?; + assert_eq!(greeting, "Hello World!"); + // For some reason, retrieving the inner HTML or text of a `` doens't work + let title = c.find(Locator::Css("title")).await?.html(false).await?; + assert!(title.contains("Index Page")); + + // Go to `/about` + c.find(Locator::Id("about-link")).await?.click().await?; + let url = c.current_url().await?; + assert!(url.as_ref().starts_with("http://localhost:8080/about")); + wait_for_checkpoint!("initial_state_not_present", 0, c); + wait_for_checkpoint!("page_visible", 1, c); + // Make sure the hardcoded text there exists + let text = c.find(Locator::Css("p")).await?.text().await?; + assert_eq!(text, "About."); + let title = c.find(Locator::Css("title")).await?.html(false).await?; + assert!(title.contains("About Page")); + // Make sure we get initial state if we refresh + c.refresh().await?; + wait_for_checkpoint!("initial_state_present", 0, c); + + Ok(()) +} diff --git a/test.sh b/test.sh index ca1b051d06..6e7d92ee17 100644 --- a/test.sh +++ b/test.sh @@ -1,13 +1,14 @@ #!/bin/bash # This script tests the given example with Bonnie -test=$1 -headless=$2 +category=$1 +example=$2 +headless=$3 # Get the path to the server executable (last line of output when we use `--no-run`) -exec=$(bonnie dev test $test test --no-run | tail -n 1) +exec=$(bonnie dev example $category $example test --no-run | tail -n 1) # Now move into the correct execution context -cd tests/$test/.perseus/server +cd examples/$category/$example/.perseus/server # And run the server itself in the background (making sure to pass through that we're testing) PERSEUS_TESTING=true $exec &