forked from rojo-rbx/rojo
Add foundations for 'rojo serve' tests
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1572,7 +1572,9 @@ dependencies = [
|
||||
name = "rojo-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"insta 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rojo 0.5.0",
|
||||
|
||||
@@ -10,6 +10,8 @@ insta = "0.10.0"
|
||||
paste = "0.1.5"
|
||||
tempfile = "3.1.0"
|
||||
reqwest = "0.9.20"
|
||||
env_logger = "0.6.2"
|
||||
log = "0.4.8"
|
||||
|
||||
# We execute Rojo via std::process::Command, so depend on it so it's built!
|
||||
rojo = { path = ".." }
|
||||
rojo = { path = ".." }
|
||||
|
||||
9
rojo-test/serve-tests/placeholder/default.project.json
Normal file
9
rojo-test/serve-tests/placeholder/default.project.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "placeholder",
|
||||
"tree": {
|
||||
"$className": "StringValue",
|
||||
"$properties": {
|
||||
"Value": "Hello, world!"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ macro_rules! gen_build_tests {
|
||||
paste::item! {
|
||||
#[test]
|
||||
fn [<build_ $test_name>]() {
|
||||
let _ = env_logger::try_init();
|
||||
run_build_test(stringify!($test_name));
|
||||
}
|
||||
}
|
||||
@@ -54,9 +55,9 @@ fn run_build_test(test_name: &str) {
|
||||
let build_test_path = get_build_tests_path();
|
||||
let working_dir = get_working_dir_path();
|
||||
|
||||
let output_dir = tempdir().expect("couldn't create temporary directory");
|
||||
|
||||
let input_path = build_test_path.join(test_name);
|
||||
|
||||
let output_dir = tempdir().expect("couldn't create temporary directory");
|
||||
let output_path = output_dir.path().join(format!("{}.rbxmx", test_name));
|
||||
|
||||
let exe_path = get_rojo_path();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
mod util;
|
||||
#![cfg(test)]
|
||||
|
||||
#[cfg(test)]
|
||||
mod build_test;
|
||||
|
||||
#[cfg(test)]
|
||||
mod serve_test;
|
||||
mod util;
|
||||
|
||||
@@ -1 +1,41 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::util::{get_rojo_path, get_serve_tests_path, get_working_dir_path};
|
||||
|
||||
#[test]
|
||||
fn serve_test() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let serve_test_path = get_serve_tests_path();
|
||||
let working_dir = get_working_dir_path();
|
||||
|
||||
let input_path = serve_test_path.join("placeholder");
|
||||
|
||||
let exe_path = get_rojo_path();
|
||||
|
||||
let mut handle = Command::new(exe_path)
|
||||
.args(&["serve", input_path.to_str().unwrap(), "--port", "35103"])
|
||||
.current_dir(working_dir)
|
||||
.spawn()
|
||||
.expect("Couldn't start Rojo");
|
||||
|
||||
loop {
|
||||
let mut response = match reqwest::get("http://localhost:35103/api/rojo") {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
log::info!("Server error, retrying: {}", err);
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let text = response.text().expect("Couldn't get response text");
|
||||
|
||||
log::info!("Got response body: {}", text);
|
||||
break;
|
||||
}
|
||||
|
||||
handle
|
||||
.kill()
|
||||
.expect("Rojo server was not running at end of test");
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@ pub fn get_rojo_path() -> PathBuf {
|
||||
|
||||
pub fn get_working_dir_path() -> PathBuf {
|
||||
let mut manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
assert!(manifest_dir.pop(), "Manifest directory did not have a parent");
|
||||
assert!(
|
||||
manifest_dir.pop(),
|
||||
"Manifest directory did not have a parent"
|
||||
);
|
||||
manifest_dir
|
||||
}
|
||||
|
||||
@@ -25,4 +28,4 @@ pub fn get_build_tests_path() -> PathBuf {
|
||||
pub fn get_serve_tests_path() -> PathBuf {
|
||||
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
manifest_dir.join("serve-tests")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user