-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
unexpected diff on assert.deepStrictEqual #51733
Comments
It happened to me as well. |
The current implementation for the diff is a quick best effort implementation and we have to change it to Myers algorithm or similar to properly detect these changes without a bad runtime. |
Would a fix to this get added to node 20? |
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-stale
|
bump |
After spending A LOT of time looking around and trying things, I don't think implementing any standard diff algorithm is going to be perfect for us. Why? Because we have a couple of edgecases which would deviate from any diff algorithm, ending up into something custom anyway:
I actually ended up implementing the myerDiff algorithm myself in the There is a couple of problems tho:
const actualInspected = inspectValue(actual);
const actualLines = StringPrototypeSplit(actualInspected, '\n');
const expectedLines = StringPrototypeSplit(inspectValue(expected), '\n'); which converts the input: {
common: {},
key1: "",
creator: "123",
}
{
creator: "123",
}, to [ '{', ' common: {},', " creator: '123',", " key1: ''", '}' ]
[ '{', " creator: '123'", '}' ] and, if you pay enough attention, in The naive solution to this problem is to do something like this: // Remove trailing comma from each line
if (typeof actual === 'object' && actual !== null) {
for (let i = 0; i < actualLines.length; i++) {
actualLines[i] = actualLines[i].replace(/,$/, '');
}
}
if (typeof expected === 'object' && expected !== null) {
for (let i = 0; i < expectedLines.length; i++) {
expectedLines[i] = expectedLines[i].replace(/,$/, '');
}
} which is NOT ideal. The problem I am pretty sure should be resolved in the
I am not sure the whole effort of implementing all these things into the new algorithm is worth it. To fix the issue OP reported, we need to tweak this check: https://github.com/nodejs/node/blob/main/lib/internal/assert/assertion_error.js#L235 right now only works if I could make that change and it should solve the issue, without adapting the algorithm I built to cover all the edge cases. What do you think? |
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com> PR-URL: nodejs#54862 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Version
v20.5.0 (tried on node 16 and 21)
Platform
([ronment]::OSVersion.VersionString) x64
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
Only comon and key1 exist so
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: