assert: truncate long strings in diffs to improve DX - #65221
Open
moshams272 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the developer experience (DX) of assertion error diffs.
Changes:
In non-colored diffs (

getStackedDiff): Truncate extremely long strings to a 15-character context around the actual difference. It replaces the rest of the identical string with...(totaling 18 characters). This keeps the output clean and readable while preserving the position of the^indicator.Comparison between before & after:
In colored diffs (

printSimpleMyersDiff): We use the same truncation strategy here as in the non-colored diffs with 10-character context around the actual difference and...(totaling 13 characters). However, while the non-colored diff only targets the first difference, the Myers diff evaluates all differences in the strings. Because the original algorithm processes character-by-character, we needed to know exactly how many identical characters exist between each difference in order to replace long identical sequences with.... So, we grouped the identical characters first to enable this truncation. (As a bonus, this grouping reduces the ANSI escape code overhead sent to the terminal).Comparison between before & after:
Tests: Update
test-assert.js/test-assert-class.jsexpectations and regenerate theassertion-color-ttysnapshot to reflect these improvements.