Skip to content

Commit

Permalink
test: added tests for custom server integration
Browse files Browse the repository at this point in the history
This involved adding the infrastructure for integration-locked example testing.
  • Loading branch information
arctic-hen7 committed Jul 4, 2022
1 parent d450a81 commit ad099ba
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
type: core
- name: index_view
type: core
- name: custom_server
type: core
steps:
- uses: actions/checkout@v2
- run: cargo install bonnie wasm-pack rust-script
Expand Down
3 changes: 2 additions & 1 deletion bonnie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ test.cmd = [
"bonnie test example-all-integrations core rx_state --headless",
"bonnie test example-all-integrations core index_view --headless",
"bonnie test example-all-integrations core set_headers --headless",
"bonnie test example-all-integrations core static_content --headless"
"bonnie test example-all-integrations core static_content --headless",
"bonnie test example-all-integrations core custom_server --headless"
]
test.desc = "runs all tests headlessly (assumes geckodriver running in background)"
test.subcommands.core.cmd = "cargo test"
Expand Down
2 changes: 1 addition & 1 deletion examples/core/basic/src/templates/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ pub async fn get_build_state(
_locale: String,
) -> RenderFnResultWithCause<IndexPageState> {
Ok(IndexPageState {
greeting: "Hello Worlds!".to_string(),
greeting: "Hello World!".to_string(),
})
}
15 changes: 9 additions & 6 deletions examples/core/custom_server/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ async fn main(c: &mut Client) -> Result<(), fantoccini::error::CmdError> {
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?;
Expand All @@ -26,11 +22,18 @@ async fn main(c: &mut Client) -> Result<(), fantoccini::error::CmdError> {
// 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);

// Check the API routes (we test with a server)
// The echo route should echo back everything we give it
c.goto("http://localhost:8080/api/echo/test").await?;
let text = c.find(Locator::Css("pre")).await?.text().await?;
assert_eq!(text, "test");
c.goto("http://localhost:8080/api/echo/blah").await?;
let text = c.find(Locator::Css("pre")).await?.text().await?;
assert_eq!(text, "blah");

Ok(())
}
11 changes: 10 additions & 1 deletion scripts/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,21 @@ fn real_main() -> i32 {
.spawn()
.expect("couldn't start test server (command execution failed)");

// Check if this example is locked to a single integration (in which case we shouldn't apply the user's integration setting)
let integration_locked = std::fs::metadata(format!("examples/{}/{}/.integration_locked", &category, &example)).is_ok();
let cargo_features = if integration_locked {
println!("The given example is locked to a specific integration. The provided integration may not be used.");
String::new()
} else {
format!("--features 'perseus-integration/{}'", &integration)
};

// We want to get an exit code from actually running the tests (which interact with the server we're running in the background), which we'll return from this process
let exit_code = {
let output = Command::new(shell_exec)
.current_dir(&format!("examples/{}/{}", &category, &example))
// TODO Confirm that this syntax works on Windows
.args([shell_param, &format!("cargo test --features 'perseus-integration/{}' -- --test-threads 1", &integration)])
.args([shell_param, &format!("cargo test {} -- --test-threads 1", &cargo_features)])
.envs(if is_headless {
vec![("PERSEUS_RUN_WASM_TESTS", "true"), ("PERSEUS_RUN_WASM_TESTS_HEADLESS", "true")]
} else {
Expand Down

0 comments on commit ad099ba

Please sign in to comment.