New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsorted keys on test.deepEquals diff. #412
Comments
Depending on the engine, object key ordering is unreliable; two different objects might indeed have two different orderings, and the inspection results of that should be faithful to the object themselves. What I can see being useful is, in addition to actual/expected, adding a "diff" result to the report? |
Unfortunately adding 'diff' looks like a breaking change (may, and probably will break most of the reporters) and I'm not sure if that's necessary here. IMHO in worst case scenario for this change would be a waste of CPU cycles, in best, and the most used one, which is Node.JS environment, it will actually improve the diffs thrown by different tap reporters. |
If you're using a reporter however, can't it sort the keys for you in order to do the diff? |
From my understanding it would require reparsing the objects from generated TAP text, which for bigger structures could be resource intensive. |
What does node’s assert.deepEqual do here? |
Node's
Jest:
Jest code tested:
I'd really lean towards jest's behavior, as it's much easier to understand and work with. |
That's fair; but this package tries particularly hard to adhere to assert's API. I looked into this; but since this package uses https://github.com/substack/object-inspect, I think that change would have to be made there - potentially behind an option. It'd be a fairly complex change, as well. |
tape matches node's assert, so I think the change would need to be first made in node before we could make it here. |
I've noticed a thing, that makes understanding what happened a little harder than it should. Whenever you
deepEqual
objects, the keys returned in a diff are not sorted anyhow, which makes diff hardly readable in your object has multiple entries. Simple naive sorting before passing to deepEquals would solve this feature, though it adds on runtime, especially if sorting would go down each level, unless we'd just sort top-level keys.Current behavior:
Expected behavior after this issue:
Simple POC/problem resolution repository: https://github.com/Palid/tape-diff-poc
See files
current-behavior.js
for current behavior andbetter-diff-behavior.js
for proposed (though naive) resolution.The text was updated successfully, but these errors were encountered: