diff --git a/src/serve_session.rs b/src/serve_session.rs index 969e7cbf..30438c26 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -245,6 +245,69 @@ mod serve_session { assert_yaml_snapshot!(view_tree(&session.tree(), &mut rm)); } + #[test] + fn script_with_meta() { + let mut imfs = Imfs::new(NoopFetcher); + + imfs.debug_load_snapshot( + "/root", + ImfsSnapshot::dir(hashmap! { + "test.lua" => ImfsSnapshot::file("This is a test."), + "test.meta.json" => ImfsSnapshot::file(r#"{ "ignoreUnknownInstances": true }"#), + }), + ); + + let session = ServeSession::new(imfs, "/root", None); + + let mut rm = RedactionMap::new(); + assert_yaml_snapshot!(view_tree(&session.tree(), &mut rm)); + } + + #[test] + fn change_script_meta() { + let (state, fetcher) = TestFetcher::new(); + + state.load_snapshot( + "/root", + ImfsSnapshot::dir(hashmap! { + "test.lua" => ImfsSnapshot::file("This is a test."), + "test.meta.json" => ImfsSnapshot::file(r#"{ "ignoreUnknownInstances": true }"#), + }), + ); + + let imfs = Imfs::new(fetcher); + let session = ServeSession::new(imfs, "/root", None); + + let mut redactions = RedactionMap::new(); + assert_yaml_snapshot!( + "change_script_meta_before", + view_tree(&session.tree(), &mut redactions) + ); + + state.load_snapshot( + "/root/test.meta.json", + ImfsSnapshot::file(r#"{ "ignoreUnknownInstances": false }"#), + ); + + let receiver = Timeout::new( + session.message_queue().subscribe_any(), + Duration::from_millis(200), + ); + state.raise_event(ImfsEvent::Modified(PathBuf::from("/root/test.meta.json"))); + + let mut rt = Runtime::new().unwrap(); + let changes = rt.block_on(receiver).unwrap(); + + assert_yaml_snapshot!( + "change_script_meta_patch", + redactions.redacted_yaml(changes) + ); + assert_yaml_snapshot!( + "change_script_meta_after", + view_tree(&session.tree(), &mut redactions) + ); + } + #[test] fn change_txt_file() { let (state, fetcher) = TestFetcher::new(); diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 26dce30d..b59898ea 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -96,7 +96,7 @@ fn snapshot_lua_file( let mut metadata = InstanceMetadata { instigating_source: Some(entry.path().to_path_buf().into()), - relevant_paths: vec![entry.path().to_path_buf()], + relevant_paths: vec![entry.path().to_path_buf(), meta_path.clone()], ..Default::default() }; diff --git a/src/snapshot_middleware/snapshots/test__client_from_imfs.snap b/src/snapshot_middleware/snapshots/test__client_from_imfs.snap index 35ef40fb..f76fb658 100644 --- a/src/snapshot_middleware/snapshots/test__client_from_imfs.snap +++ b/src/snapshot_middleware/snapshots/test__client_from_imfs.snap @@ -9,6 +9,7 @@ metadata: Path: /foo.client.lua relevant_paths: - /foo.client.lua + - /foo.meta.json name: foo class_name: LocalScript properties: diff --git a/src/snapshot_middleware/snapshots/test__module_from_imfs.snap b/src/snapshot_middleware/snapshots/test__module_from_imfs.snap index 3ad3d835..d6bb90f7 100644 --- a/src/snapshot_middleware/snapshots/test__module_from_imfs.snap +++ b/src/snapshot_middleware/snapshots/test__module_from_imfs.snap @@ -9,6 +9,7 @@ metadata: Path: /foo.lua relevant_paths: - /foo.lua + - /foo.meta.json name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/test__module_with_meta.snap b/src/snapshot_middleware/snapshots/test__module_with_meta.snap index d54f1133..15b911f3 100644 --- a/src/snapshot_middleware/snapshots/test__module_with_meta.snap +++ b/src/snapshot_middleware/snapshots/test__module_with_meta.snap @@ -9,6 +9,7 @@ metadata: Path: /foo.lua relevant_paths: - /foo.lua + - /foo.meta.json name: foo class_name: ModuleScript properties: diff --git a/src/snapshot_middleware/snapshots/test__script_with_meta.snap b/src/snapshot_middleware/snapshots/test__script_with_meta.snap index ce267c6f..2c7dbf43 100644 --- a/src/snapshot_middleware/snapshots/test__script_with_meta.snap +++ b/src/snapshot_middleware/snapshots/test__script_with_meta.snap @@ -9,6 +9,7 @@ metadata: Path: /foo.server.lua relevant_paths: - /foo.server.lua + - /foo.meta.json name: foo class_name: Script properties: diff --git a/src/snapshot_middleware/snapshots/test__server_from_imfs.snap b/src/snapshot_middleware/snapshots/test__server_from_imfs.snap index 3c9c0070..b9964d27 100644 --- a/src/snapshot_middleware/snapshots/test__server_from_imfs.snap +++ b/src/snapshot_middleware/snapshots/test__server_from_imfs.snap @@ -9,6 +9,7 @@ metadata: Path: /foo.server.lua relevant_paths: - /foo.server.lua + - /foo.meta.json name: foo class_name: Script properties: diff --git a/src/snapshots/serve_session__change_script_meta_after.snap b/src/snapshots/serve_session__change_script_meta_after.snap new file mode 100644 index 00000000..dacd98cc --- /dev/null +++ b/src/snapshots/serve_session__change_script_meta_after.snap @@ -0,0 +1,30 @@ +--- +source: src/serve_session.rs +expression: "view_tree(&session.tree(), &mut redactions)" +--- +id: id-1 +name: root +class_name: Folder +properties: {} +metadata: + ignore_unknown_instances: false + instigating_source: + Path: /root + relevant_paths: + - /root +children: + - id: id-2 + name: test + class_name: ModuleScript + properties: + Source: + Type: String + Value: This is a test. + metadata: + ignore_unknown_instances: false + instigating_source: + Path: /root/test.lua + relevant_paths: + - /root/test.lua + - /root/test.meta.json + children: [] diff --git a/src/snapshots/serve_session__change_script_meta_before.snap b/src/snapshots/serve_session__change_script_meta_before.snap new file mode 100644 index 00000000..dcf06e97 --- /dev/null +++ b/src/snapshots/serve_session__change_script_meta_before.snap @@ -0,0 +1,30 @@ +--- +source: src/serve_session.rs +expression: "view_tree(&session.tree(), &mut redactions)" +--- +id: id-1 +name: root +class_name: Folder +properties: {} +metadata: + ignore_unknown_instances: false + instigating_source: + Path: /root + relevant_paths: + - /root +children: + - id: id-2 + name: test + class_name: ModuleScript + properties: + Source: + Type: String + Value: This is a test. + metadata: + ignore_unknown_instances: true + instigating_source: + Path: /root/test.lua + relevant_paths: + - /root/test.lua + - /root/test.meta.json + children: [] diff --git a/src/snapshots/serve_session__change_script_meta_patch.snap b/src/snapshots/serve_session__change_script_meta_patch.snap new file mode 100644 index 00000000..1330da20 --- /dev/null +++ b/src/snapshots/serve_session__change_script_meta_patch.snap @@ -0,0 +1,19 @@ +--- +source: src/serve_session.rs +expression: redactions.redacted_yaml(changes) +--- +- 1 +- - removed: [] + added: [] + updated: + - id: id-2 + changed_name: ~ + changed_class_name: ~ + changed_properties: {} + changed_metadata: + ignore_unknown_instances: false + instigating_source: + Path: /root/test.lua + relevant_paths: + - /root/test.lua + - /root/test.meta.json diff --git a/src/snapshots/serve_session__script_with_meta.snap b/src/snapshots/serve_session__script_with_meta.snap new file mode 100644 index 00000000..81247ba5 --- /dev/null +++ b/src/snapshots/serve_session__script_with_meta.snap @@ -0,0 +1,30 @@ +--- +source: src/serve_session.rs +expression: "view_tree(&session.tree(), &mut rm)" +--- +id: id-1 +name: root +class_name: Folder +properties: {} +metadata: + ignore_unknown_instances: false + instigating_source: + Path: /root + relevant_paths: + - /root +children: + - id: id-2 + name: test + class_name: ModuleScript + properties: + Source: + Type: String + Value: This is a test. + metadata: + ignore_unknown_instances: true + instigating_source: + Path: /root/test.lua + relevant_paths: + - /root/test.lua + - /root/test.meta.json + children: []