Skip to content

Commit

Permalink
[ofl] add --cargo-before flag to ofl serve-then-run
Browse files Browse the repository at this point in the history
  • Loading branch information
anp committed Oct 18, 2020
1 parent 0464513 commit 1e19b9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 11 additions & 9 deletions dom/examples/todo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
9 changes: 9 additions & 0 deletions ofl/src/server/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// args to pass the command
#[options(free)]
args: Vec<String>,
Expand All @@ -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() {
Expand Down

0 comments on commit 1e19b9d

Please sign in to comment.