diff --git a/.cargo/config.toml b/.cargo/config.toml index 5ecf7fe64..f75263a7b 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -88,7 +88,12 @@ test-dom-lib-browser = "wa-test dom" test-dom-drivertest = "wa-test dom/examples/drivertest" test-dom-hacking = "wa-test dom/examples/hacking" test-dom-todo = "wa-test dom/examples/todo" -test-dom-todo-e2e = "ofl serve-then-run --cwd dom/examples/todo/e2e -- npx cypress run" +test-dom-todo-e2e = """ +ofl serve-then-run + --cargo-before build-dom-todo + --cwd dom/examples/todo/e2e -- +npx cypress run +""" # standalones test-dom = "test --package moxie-dom --package ssr-poc --all-targets" diff --git a/dom/examples/todo/README.md b/dom/examples/todo/README.md index d10d46dca..b229ea685 100644 --- a/dom/examples/todo/README.md +++ b/dom/examples/todo/README.md @@ -7,10 +7,12 @@ Commands all assume the working directory is the repository root. Build the example and start the project's local HTTP server: ``` -$ cargo build-dom-todo +$ cargo build-dom-todo # for live-watching rebuilds use `cargo dom-flow` $ cargo ofl serve ``` +In VSCode the same can be accomplished by running the `dom crates` and `project server` tasks. + ## Using To use the example locally, follow the directions for [serving](#serving) the project and @@ -25,18 +27,18 @@ Unit & integration tests can be run with `cargo test-dom-todo`. End-to-end tests are run with [Cypress](https://cypress.io) which requires [Node.js](https://nodejs.org) to run. -The tests require a running HTTP server and a current build. The `test-dom-todo-e2e` cargo command -starts an HTTP server for the test and only requires a build to have been run first: +If you've already followed the [serving](#serving) instructions the e2e tests can be run from the +Cypress UI directly. Start the test runner with the `cypress` VSCode task or run the following: ``` -$ cargo build-dom-todo -$ cargo test-dom-todo-e2e +$ cd dom/examples/todo/e2e; npx cypress run ``` -If you've already followed the [serving](#serving) instructions the e2e tests should be run -directly: +#### One-off + +The tests require a running HTTP server and a current build. The `test-dom-todo-e2e` cargo command +runs a build, and starts an HTTP server for the test before running it: ``` -$ cd dom/examples/todo/e2e -$ npx cypress run +$ cargo test-dom-todo-e2e ``` diff --git a/ofl/src/server/run.rs b/ofl/src/server/run.rs index a6510396a..ea3ce4d11 100644 --- a/ofl/src/server/run.rs +++ b/ofl/src/server/run.rs @@ -19,6 +19,8 @@ pub struct RunOpts { cmd: String, /// working directory for the command cwd: PathBuf, + /// cargo command to run before launching tests + cargo_before: Option, /// args to pass the command #[options(free)] args: Vec, @@ -37,6 +39,13 @@ impl RunOpts { } }); + if let Some(cargo_cmd) = self.cargo_before { + let status = Command::new("cargo").arg(&cargo_cmd).status()?; + if !status.success() { + bail!("`cargo {}` failed with status {:?}", cargo_cmd, status); + } + } + info!("checking server..."); let url = format!("http://[::1]:{}", self.port); while reqwest::blocking::get(&url).is_err() {