Clarify "flattening" step in SB3 roundtrip test

This commit is contained in:
Christopher Willis-Ford 2017-06-13 13:58:34 -07:00
parent 4b1aad5099
commit 1bf1808826

View file

@ -95,11 +95,11 @@ test('sb3-roundtrip', t => {
});
const serializeAndDeserialize = installThings.then(() => {
// `Clone.simple` here helps in two ways:
// Doing a JSON `stringify` and `parse` here more accurately simulate a save/load cycle. In particular:
// 1. it ensures that any non-serializable data is thrown away, and
// 2. `sb3.deserialize` does some `hasOwnProperty` checks which fail on the object returned by `sb3.serialize`
// due to its inheritance structure.
const serializedState = Clone.simple(sb3.serialize(runtime1));
// 2. `sb3.deserialize` and its helpers do some `hasOwnProperty` checks which fail on the object returned by
// `sb3.serialize` but succeed if that object is "flattened" in this way.
const serializedState = JSON.parse(JSON.stringify(sb3.serialize(runtime1)));
return sb3.deserialize(serializedState, runtime2);
});