-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
assert: avoid expensive diff for large values #62798
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ const kReadableOperator = { | |
|
|
||
| const kMaxShortStringLength = 12; | ||
| const kMaxLongStringLength = 512; | ||
| const kMaxDiffLineCount = 1000; | ||
| const kMaxDiffLinesToShow = 50; | ||
|
|
||
| const kMethodsWithCustomMessageDiff = new SafeSet() | ||
| .add('deepStrictEqual') | ||
|
|
@@ -182,6 +184,13 @@ function isSimpleDiff(actual, inspectedActual, expected, inspectedExpected) { | |
| return typeof actual !== 'object' || actual === null || typeof expected !== 'object' || expected === null; | ||
| } | ||
|
|
||
| function getTruncatedDiffValue(lines) { | ||
| if (lines.length > kMaxDiffLinesToShow) { | ||
| return `${ArrayPrototypeJoin(ArrayPrototypeSlice(lines, 0, kMaxDiffLinesToShow), '\n')}\n...`; | ||
| } | ||
| return ArrayPrototypeJoin(lines, '\n'); | ||
| } | ||
|
|
||
| function createErrDiff(actual, expected, operator, customMessage, diffType = 'simple') { | ||
| operator = checkOperator(actual, expected, operator); | ||
|
|
||
|
|
@@ -213,6 +222,13 @@ function createErrDiff(actual, expected, operator, customMessage, diffType = 'si | |
| message = ArrayPrototypeJoin(inspectedSplitActual, '\n'); | ||
| } | ||
| header = ''; | ||
| } else if ( | ||
| diffType !== 'full' && | ||
| inspectedSplitActual.length + inspectedSplitExpected.length > kMaxDiffLineCount | ||
| ) { | ||
| message = `\n${colors.green}+${colors.white} ${getTruncatedDiffValue(inspectedSplitActual)}\n` + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded colors bypasses the partialDeepStrictEqual coloring convention
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the truncated diff path to follow the partialDeepStrictEqual coloring convention. |
||
| `${colors.red}-${colors.white} ${getTruncatedDiffValue(inspectedSplitExpected)}`; | ||
| skipped = true; | ||
| } else { | ||
| const checkCommaDisparity = actual != null && typeof actual === 'object'; | ||
| const diff = myersDiff(inspectedSplitActual, inspectedSplitExpected, checkCommaDisparity); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can completely hide the real diff when users actually need it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Narrowed the skip path to large root-level mismatches only. Large values with the same root representation still use the normal line diff, and I added a regression test for that case.