mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-26 15:46:28 +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
|
source: rojo-test/src/serve_test.rs
|
||||||
expression: read_result
|
expression: read_result
|
||||||
---
|
---
|
||||||
sessionId: id-1
|
|
||||||
messageCursor: 0
|
|
||||||
instances:
|
instances:
|
||||||
id-2:
|
id-2:
|
||||||
Id: id-2
|
Id: id-2
|
||||||
@@ -14,3 +12,5 @@ instances:
|
|||||||
Children: []
|
Children: []
|
||||||
Metadata:
|
Metadata:
|
||||||
ignoreUnknownInstances: true
|
ignoreUnknownInstances: true
|
||||||
|
messageCursor: 0
|
||||||
|
sessionId: id-1
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
source: rojo-test/src/serve_test.rs
|
source: rojo-test/src/serve_test.rs
|
||||||
expression: info
|
expression: info
|
||||||
---
|
---
|
||||||
sessionId: id-1
|
|
||||||
serverVersion: 0.6.0-dev
|
|
||||||
protocolVersion: 3
|
|
||||||
expectedPlaceIds: ~
|
expectedPlaceIds: ~
|
||||||
|
protocolVersion: 3
|
||||||
rootInstanceId: id-2
|
rootInstanceId: id-2
|
||||||
|
serverVersion: 0.6.0-dev
|
||||||
|
sessionId: id-1
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
source: rojo-test/src/serve_test.rs
|
source: rojo-test/src/serve_test.rs
|
||||||
expression: read_result
|
expression: read_result
|
||||||
---
|
---
|
||||||
sessionId: id-1
|
|
||||||
messageCursor: 0
|
|
||||||
instances:
|
instances:
|
||||||
id-2:
|
id-2:
|
||||||
Id: id-2
|
Id: id-2
|
||||||
@@ -17,3 +15,5 @@ instances:
|
|||||||
Children: []
|
Children: []
|
||||||
Metadata:
|
Metadata:
|
||||||
ignoreUnknownInstances: false
|
ignoreUnknownInstances: false
|
||||||
|
messageCursor: 0
|
||||||
|
sessionId: id-1
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
source: rojo-test/src/serve_test.rs
|
source: rojo-test/src/serve_test.rs
|
||||||
expression: info
|
expression: info
|
||||||
---
|
---
|
||||||
sessionId: id-1
|
|
||||||
serverVersion: 0.6.0-dev
|
|
||||||
protocolVersion: 3
|
|
||||||
expectedPlaceIds: ~
|
expectedPlaceIds: ~
|
||||||
|
protocolVersion: 3
|
||||||
rootInstanceId: id-2
|
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 insta::assert_yaml_snapshot;
|
||||||
|
|
||||||
use crate::serve_util::run_serve_test;
|
use crate::serve_util::{intern_read_response, run_serve_test};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty() {
|
fn empty() {
|
||||||
@@ -12,15 +12,37 @@ fn empty() {
|
|||||||
let root_id = info.root_instance_id;
|
let root_id = info.root_instance_id;
|
||||||
|
|
||||||
let info = redactions.redacted_yaml(info);
|
let info = redactions.redacted_yaml(info);
|
||||||
|
|
||||||
assert_yaml_snapshot!(info);
|
assert_yaml_snapshot!(info);
|
||||||
|
|
||||||
let read_result = session.get_api_read(root_id).unwrap();
|
let read_result = session.get_api_read(root_id).unwrap();
|
||||||
|
intern_read_response(&mut redactions, &read_result, root_id);
|
||||||
redactions.intern_iter(read_result.instances.keys().copied());
|
|
||||||
|
|
||||||
let read_result = redactions.redacted_yaml(read_result);
|
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);
|
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");
|
let snapshot_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("serve-test-snapshots");
|
||||||
settings.set_snapshot_path(snapshot_path);
|
settings.set_snapshot_path(snapshot_path);
|
||||||
|
settings.set_sort_maps(true);
|
||||||
|
|
||||||
let mut redactions = RedactionMap::new();
|
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));
|
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 {
|
fn get_port_number() -> usize {
|
||||||
static NEXT_PORT_NUMBER: AtomicUsize = AtomicUsize::new(35103);
|
static NEXT_PORT_NUMBER: AtomicUsize = AtomicUsize::new(35103);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user