ottypes / json1

This is an operational transform type replacement for ottypes/json0
314 stars 27 forks source link

Verify immutability with Object.freeze #10

Open curran opened 5 years ago

curran commented 5 years ago

This issue is about improving the approach taken in the tests for checking immutability.

A quote from the original discussion of this idea in #8:

A better way to verify immutability would be to recursively call Object.freeze on all inputs to all the functions in all tests. The nice thing about that approach is that if any tests inappropriately modify data, the stack trace will point to the exact source of the error. If we do that, we probably shouldn't need special immutability test cases at all. --@josephg

josephg commented 4 years ago

This is a good idea, but its worth noting that modifying something frozen with Object.freeze will only throw an exception in a strict context. I think this should be ok since the json1 library is in a strict context now we're using typescript; but I'm still slightly nervous that the tests might silently pass.

I've inlined a small fuzzer into test.js which uses this approach. (It should probably be moved out)