Skip to content

Commit

Permalink
fix: fixed up tests
Browse files Browse the repository at this point in the history
These won't run yet because several still need to be written.
  • Loading branch information
arctic-hen7 committed Feb 2, 2022
1 parent 55c21eb commit 6f979eb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
20 changes: 13 additions & 7 deletions bonnie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/core/state_generation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
4 changes: 4 additions & 0 deletions examples/core/unreactive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
36 changes: 36 additions & 0 deletions examples/core/unreactive/tests/main.rs
Original file line number Diff line number Diff line change
@@ -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 `<title>` 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(())
}
9 changes: 5 additions & 4 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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 &

Expand Down

0 comments on commit 6f979eb

Please sign in to comment.