Add test for folder of scripts being mutated

This commit is contained in:
Lucien Greathouse
2019-10-16 16:55:55 -07:00
parent 40540c3637
commit 56f5a61362
12 changed files with 167 additions and 15 deletions

View File

@@ -2,7 +2,7 @@ use std::fs;
use insta::assert_yaml_snapshot;
use crate::serve_util::run_serve_test;
use crate::serve_util::{intern_read_response, run_serve_test};
#[test]
fn empty() {
@@ -12,15 +12,37 @@ fn empty() {
let root_id = info.root_instance_id;
let info = redactions.redacted_yaml(info);
assert_yaml_snapshot!(info);
let read_result = session.get_api_read(root_id).unwrap();
redactions.intern_iter(read_result.instances.keys().copied());
intern_read_response(&mut redactions, &read_result, root_id);
let read_result = redactions.redacted_yaml(read_result);
assert_yaml_snapshot!(read_result);
});
}
#[test]
fn scripts() {
run_serve_test("scripts", |session, mut redactions| {
let info = session.get_api_rojo().unwrap();
let root_id = info.root_instance_id;
let info = redactions.redacted_yaml(info);
assert_yaml_snapshot!(info);
let read_result = session.get_api_read(root_id).unwrap();
intern_read_response(&mut redactions, &read_result, root_id);
let read_result = redactions.redacted_yaml(read_result);
assert_yaml_snapshot!(read_result);
fs::write(session.path().join("foo.lua"), "Updated foo!").unwrap();
let subscribe_result = session.get_api_subscribe(0).unwrap();
let subscribe_result = redactions.redacted_yaml(subscribe_result);
assert_yaml_snapshot!(subscribe_result);
let read_result = session.get_api_read(root_id).unwrap();
let read_result = redactions.redacted_yaml(read_result);
assert_yaml_snapshot!(read_result);
});
}

View File

@@ -22,6 +22,7 @@ pub fn run_serve_test(test_name: &str, callback: impl FnOnce(TestServeSession, R
let snapshot_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("serve-test-snapshots");
settings.set_snapshot_path(snapshot_path);
settings.set_sort_maps(true);
let mut redactions = RedactionMap::new();
@@ -34,6 +35,22 @@ pub fn run_serve_test(test_name: &str, callback: impl FnOnce(TestServeSession, R
settings.bind(move || callback(session, redactions));
}
/// Intern the response to Rojo's read API, doing traversal in a deterministic
/// order.
pub fn intern_read_response(
redactions: &mut RedactionMap,
response: &ReadResponse,
root_id: RbxId,
) {
redactions.intern(root_id);
let root_instance = response.instances.get(&root_id).unwrap();
for &child_id in root_instance.children.iter() {
intern_read_response(redactions, response, child_id);
}
}
fn get_port_number() -> usize {
static NEXT_PORT_NUMBER: AtomicUsize = AtomicUsize::new(35103);