You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-27 03:01:03 +02:00
Add xtask command for running web-tests. (#2743)
Currently, to run the tests that are located in the `tests` directory (the js tests), one has to navigate to the directory and run `npm test` or `npm start`. We now have a way of automating such task execution using the binary in the `xtask` directory. This pr makes use of this by introducing a new command `cargo xtask web-tests` that can be run from anywhere in the repo to run the tests in the `tests` directory. --------- Co-authored-by: Eric Githinji <egithinji@google.com>
This commit is contained in:
@ -14,6 +14,9 @@ used mainly in the [CI](../github/workflows/build.yml) to serve the book on port
|
|||||||
`localhost:8080` such that the test runner can access it. This mode is used when
|
`localhost:8080` such that the test runner can access it. This mode is used when
|
||||||
`npm start` or `npm test` is executed.
|
`npm start` or `npm test` is executed.
|
||||||
|
|
||||||
|
> **Tip:** Use `cargo xtask web-tests` to run the tests in this directory from
|
||||||
|
> anywhere in the repository.
|
||||||
|
|
||||||
For local testing and quick iterations it is possible to use `mdbook serve`
|
For local testing and quick iterations it is possible to use `mdbook serve`
|
||||||
which creates a small HTTP server on port 3000 by default. There is a special
|
which creates a small HTTP server on port 3000 by default. There is a special
|
||||||
config that is invoked with `npm run test-mdbook` that uses
|
config that is invoked with `npm run test-mdbook` that uses
|
||||||
|
@ -45,6 +45,7 @@ fn execute_task() -> Result<()> {
|
|||||||
let task = Args::parse().task;
|
let task = Args::parse().task;
|
||||||
match task.as_str() {
|
match task.as_str() {
|
||||||
"install-tools" => install_tools()?,
|
"install-tools" => install_tools()?,
|
||||||
|
"web-tests" => run_web_tests()?,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow!(unrecognized_task_string(task.as_str())));
|
return Err(anyhow!(unrecognized_task_string(task.as_str())));
|
||||||
}
|
}
|
||||||
@ -95,10 +96,34 @@ fn install_tools() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_web_tests() -> Result<()> {
|
||||||
|
println!("Running web tests...");
|
||||||
|
|
||||||
|
let path_to_tests_dir = Path::new(env!("CARGO_WORKSPACE_DIR")).join("tests");
|
||||||
|
|
||||||
|
let status = Command::new("npm")
|
||||||
|
.current_dir(path_to_tests_dir.to_str().unwrap())
|
||||||
|
.arg("test")
|
||||||
|
.status()
|
||||||
|
.expect("Failed to execute npm test");
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
let error_message = format!(
|
||||||
|
"Command 'cargo web-tests' exited with status code: {}",
|
||||||
|
status.code().unwrap()
|
||||||
|
);
|
||||||
|
return Err(anyhow!(error_message));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - https://github.com/google/comprehensive-rust/issues/2741: Replace this with Clap
|
||||||
fn unrecognized_task_string(task: &str) -> String {
|
fn unrecognized_task_string(task: &str) -> String {
|
||||||
format!(
|
format!(
|
||||||
"Unrecognized task '{task}'. Available tasks:
|
"Unrecognized task '{task}'. Available tasks:
|
||||||
|
|
||||||
install-tools Installs the tools the project depends on."
|
install-tools Installs the tools the project depends on.
|
||||||
|
web-tests Runs the web driver tests in the tests directory."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user