Improve serve snapshot test ergonomics

This commit is contained in:
Lucien Greathouse
2019-10-16 17:36:13 -07:00
parent cc68d57f11
commit 3880708e1d
5 changed files with 46 additions and 45 deletions

View File

@@ -2,22 +2,18 @@ use std::fs;
use insta::assert_yaml_snapshot;
use crate::serve_util::{intern_read_response, run_serve_test};
use crate::serve_util::{run_serve_test, InternAndRedact};
#[test]
fn empty() {
run_serve_test("empty", |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);
assert_yaml_snapshot!(redactions.redacted_yaml(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);
let read_response = session.get_api_read(root_id).unwrap();
assert_yaml_snapshot!(read_response.intern_and_redact(&mut redactions, root_id));
});
}
@@ -27,23 +23,18 @@ fn scripts() {
let info = session.get_api_rojo().unwrap();
let root_id = info.root_instance_id;
let info = redactions.redacted_yaml(info);
assert_yaml_snapshot!(info);
assert_yaml_snapshot!(redactions.redacted_yaml(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);
let read_response = session.get_api_read(root_id).unwrap();
assert_yaml_snapshot!(read_response.intern_and_redact(&mut redactions, root_id));
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 subscribe_response = session.get_api_subscribe(0).unwrap();
assert_yaml_snapshot!(redactions.redacted_yaml(subscribe_response));
let read_result = session.get_api_read(root_id).unwrap();
let read_result = redactions.redacted_yaml(read_result);
assert_yaml_snapshot!(read_result);
let read_response = session.get_api_read(root_id).unwrap();
assert_yaml_snapshot!(read_response.intern_and_redact(&mut redactions, root_id));
});
}
@@ -51,25 +42,15 @@ fn scripts() {
fn just_txt() {
run_serve_test("just-txt.txt", |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);
assert_yaml_snapshot!(redactions.redacted_yaml(info));
let read_result = session.get_api_read(root_id).unwrap();
redactions.intern_iter(read_result.instances.keys().copied());
let read_result = redactions.redacted_yaml(read_result);
assert_yaml_snapshot!(read_result);
let read_response = session.get_api_read(root_id).unwrap();
assert_yaml_snapshot!(read_response.intern_and_redact(&mut redactions, root_id));
fs::write(session.path(), "Changed content!").unwrap();
// TODO: Directly served files currently don't trigger changed events!
// let subscribe_result = session.get_api_subscribe(0).unwrap();
// let subscribe_result = redactions.redacted_yaml(subscribe_result);
// assert_yaml_snapshot!(subscribe_result);
});
}