You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Order-sensitive diff on expect.arrayContaining failure #8913
I'm facing a design choice. To produce an order-agnostic diff, I either:
Add a symmetricOrder(other: Array<T>): ArrayContaining<T> method to ArrayContaining, and make ArrayContaining responsible for producing an array in the order of the actual array, or
Having created a getArrayContainingDifference function, similar to getObjectsDifference, in the diff package, I make getArrayContainingDifference responsible for producing an order-agnostic diff in full (with some coupling to ArrayContaining).
I have come to realise that I can fix this diffing issue only at the top level, and that any nested ArrayContaining will still diff incorrectly. The diff engine relies on the pretty-print engine to handle nested objects and arrays, but the fix needs to live in the diff engine because only the diff engine has awareness of both the expected and actual arrays. Fixing this issue at any level of nesting requires that the recursion that handles nesting moves out of the pretty-print engine, and into the diff engine, but that’s a very big change that I imagine requires longer discussion.
Activity
btomaj commentedon Nov 4, 2025
I'm working on a fix for this.
btomaj commentedon Nov 5, 2025
I'm facing a design choice. To produce an order-agnostic diff, I either:
symmetricOrder(other: Array<T>): ArrayContaining<T>method toArrayContaining, and makeArrayContainingresponsible for producing an array in the order of the actual array, orgetArrayContainingDifferencefunction, similar togetObjectsDifference, in the diff package, I makegetArrayContainingDifferenceresponsible for producing an order-agnostic diff in full (with some coupling toArrayContaining).I need input from a maintainer.
ghostd commentedon Nov 5, 2025
@btomaj interesting question, i just commented another issue which could be related
[-]Incorrect diff on arrayContaining failure[/-][+]Order-sensitive diff on arrayContaining failure[/+][-]Order-sensitive diff on arrayContaining failure[/-][+]Order-sensitive diff on expect.arrayContaining failure[/+]btomaj commentedon Nov 9, 2025
I have come to realise that I can fix this diffing issue only at the top level, and that any nested ArrayContaining will still diff incorrectly. The diff engine relies on the pretty-print engine to handle nested objects and arrays, but the fix needs to live in the diff engine because only the diff engine has awareness of both the expected and actual arrays. Fixing this issue at any level of nesting requires that the recursion that handles nesting moves out of the pretty-print engine, and into the diff engine, but that’s a very big change that I imagine requires longer discussion.
Looking for input.
feat(diff): ArrayContaining diff is order-agnostic vitest-dev#8913
fix(diff): ArrayContaining diff is order-agnostic vitest-dev#8913
fix(diff): ArrayContaining diff is order-agnostic vitest-dev#8913
btomaj commentedon Jul 18, 2026
@sheremet-va was this discussed? Was there an outcome?
sheremet-va commentedon Aug 28, 2026
We think it
expect.arrayContainingdiff should not be order sensitivebtomaj commentedon Sep 8, 2026
@sheremet-va thank you for confirming. Is my PR on the right track?