mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Add test for folder of scripts being mutated
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: read_result
|
||||
---
|
||||
sessionId: id-1
|
||||
messageCursor: 0
|
||||
instances:
|
||||
id-2:
|
||||
Id: id-2
|
||||
@@ -14,3 +12,5 @@ instances:
|
||||
Children: []
|
||||
Metadata:
|
||||
ignoreUnknownInstances: true
|
||||
messageCursor: 0
|
||||
sessionId: id-1
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: info
|
||||
---
|
||||
sessionId: id-1
|
||||
serverVersion: 0.6.0-dev
|
||||
protocolVersion: 3
|
||||
expectedPlaceIds: ~
|
||||
protocolVersion: 3
|
||||
rootInstanceId: id-2
|
||||
serverVersion: 0.6.0-dev
|
||||
sessionId: id-1
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: read_result
|
||||
---
|
||||
sessionId: id-1
|
||||
messageCursor: 0
|
||||
instances:
|
||||
id-2:
|
||||
Id: id-2
|
||||
@@ -17,3 +15,5 @@ instances:
|
||||
Children: []
|
||||
Metadata:
|
||||
ignoreUnknownInstances: false
|
||||
messageCursor: 0
|
||||
sessionId: id-1
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: info
|
||||
---
|
||||
sessionId: id-1
|
||||
serverVersion: 0.6.0-dev
|
||||
protocolVersion: 3
|
||||
expectedPlaceIds: ~
|
||||
protocolVersion: 3
|
||||
rootInstanceId: id-2
|
||||
serverVersion: 0.6.0-dev
|
||||
sessionId: id-1
|
||||
|
||||
42
rojo-test/serve-test-snapshots/serve_test__scripts-2.snap
Normal file
42
rojo-test/serve-test-snapshots/serve_test__scripts-2.snap
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: read_result
|
||||
---
|
||||
instances:
|
||||
id-2:
|
||||
Id: id-2
|
||||
Parent: ~
|
||||
Name: scripts
|
||||
ClassName: Folder
|
||||
Properties: {}
|
||||
Children:
|
||||
- id-3
|
||||
- id-4
|
||||
Metadata:
|
||||
ignoreUnknownInstances: false
|
||||
id-3:
|
||||
Id: id-3
|
||||
Parent: id-2
|
||||
Name: bar
|
||||
ClassName: Script
|
||||
Properties:
|
||||
Source:
|
||||
Type: String
|
||||
Value: "-- Hello, from bar!"
|
||||
Children: []
|
||||
Metadata:
|
||||
ignoreUnknownInstances: false
|
||||
id-4:
|
||||
Id: id-4
|
||||
Parent: id-2
|
||||
Name: foo
|
||||
ClassName: ModuleScript
|
||||
Properties:
|
||||
Source:
|
||||
Type: String
|
||||
Value: "-- Hello, from foo!"
|
||||
Children: []
|
||||
Metadata:
|
||||
ignoreUnknownInstances: false
|
||||
messageCursor: 0
|
||||
sessionId: id-1
|
||||
18
rojo-test/serve-test-snapshots/serve_test__scripts-3.snap
Normal file
18
rojo-test/serve-test-snapshots/serve_test__scripts-3.snap
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: subscribe_result
|
||||
---
|
||||
messageCursor: 1
|
||||
messages:
|
||||
- removedInstances: []
|
||||
addedInstances: {}
|
||||
updatedInstances:
|
||||
- id: id-4
|
||||
changedName: ~
|
||||
changedClassName: ~
|
||||
changedProperties:
|
||||
Source:
|
||||
Type: String
|
||||
Value: Updated foo!
|
||||
changedMetadata: ~
|
||||
sessionId: id-1
|
||||
42
rojo-test/serve-test-snapshots/serve_test__scripts-4.snap
Normal file
42
rojo-test/serve-test-snapshots/serve_test__scripts-4.snap
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: read_result
|
||||
---
|
||||
instances:
|
||||
id-2:
|
||||
Id: id-2
|
||||
Parent: ~
|
||||
Name: scripts
|
||||
ClassName: Folder
|
||||
Properties: {}
|
||||
Children:
|
||||
- id-3
|
||||
- id-4
|
||||
Metadata:
|
||||
ignoreUnknownInstances: false
|
||||
id-3:
|
||||
Id: id-3
|
||||
Parent: id-2
|
||||
Name: bar
|
||||
ClassName: Script
|
||||
Properties:
|
||||
Source:
|
||||
Type: String
|
||||
Value: "-- Hello, from bar!"
|
||||
Children: []
|
||||
Metadata:
|
||||
ignoreUnknownInstances: false
|
||||
id-4:
|
||||
Id: id-4
|
||||
Parent: id-2
|
||||
Name: foo
|
||||
ClassName: ModuleScript
|
||||
Properties:
|
||||
Source:
|
||||
Type: String
|
||||
Value: Updated foo!
|
||||
Children: []
|
||||
Metadata:
|
||||
ignoreUnknownInstances: false
|
||||
messageCursor: 1
|
||||
sessionId: id-1
|
||||
9
rojo-test/serve-test-snapshots/serve_test__scripts.snap
Normal file
9
rojo-test/serve-test-snapshots/serve_test__scripts.snap
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
source: rojo-test/src/serve_test.rs
|
||||
expression: info
|
||||
---
|
||||
expectedPlaceIds: ~
|
||||
protocolVersion: 3
|
||||
rootInstanceId: id-2
|
||||
serverVersion: 0.6.0-dev
|
||||
sessionId: id-1
|
||||
1
rojo-test/serve-tests/scripts/bar.server.lua
Normal file
1
rojo-test/serve-tests/scripts/bar.server.lua
Normal file
@@ -0,0 +1 @@
|
||||
-- Hello, from bar!
|
||||
1
rojo-test/serve-tests/scripts/foo.lua
Normal file
1
rojo-test/serve-tests/scripts/foo.lua
Normal file
@@ -0,0 +1 @@
|
||||
-- Hello, from foo!
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user