feat(testing): improved strings diff#948
Conversation
|
I created a small gist just to get a sense of how the new diff looks visually -- it seems to be working ok when both sides of the assertion are single-line string. Things get a little weird when the part of the string that differs contains a mix of newlines and spaces though. When the strings are completely different, or when the string is inside an object or an array, it reverts back to the old diff. In the case where the string is nested in an object or array, I guess it's ok, but having to different diffs for strings seems a bit weird to me. Here's the gist I used https://gist.github.com/wperron/77ba7b170799cc7b925c1734b38624e1 |
|
Thanks for linking the gist Yes I wasn't too sure how to handle both multilines and word diffs. I was actually waiting for some input about it. I can see multiple paths to takes:
Currently it's an "autodetect" which choose between word-diff/multiline-diff based on the changes ratio and the number of lines, so that's why a full line diff revert back to old diff system but it's kind of hack, I'm not very convinced myself it 😅 If you have others suggestions please let me know 👍 For nested strings, I chose to not support them because I think it would quite a lof of work because of how diffs are computed. From my understanding, the generic Current behaviour where both root operands must be strings seems fine to me, in the sense of when you're asserting two strings together you'd probably like to see a detailed diff between them, while if you assert whole objects/arrays you're probably more insterested in a more global view. If someone wants detailed string diff within a complex structure, one can always assert it explicitely by checking members |
|
Looks very useful 👍 Does anyone have any concern about introducing this? |
kt3k
left a comment
There was a problem hiding this comment.
@lowlighter LGTM. Great feature!









This add a specialized tokenizer that is called when both operands are string before entering
diff(), making changes in large strings assertions more visible.A word diff has been implemented (similar to

git diff --word-diff):As the above is not practical when a lot of words have been changed, a multiline diff has also been implemented:

Todo
diff()andbuildMessage()_diff_testasserts_testCloses #929