-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
DRAFT: chore: vitest iterable equality temporary workaround #2629
DRAFT: chore: vitest iterable equality temporary workaround #2629
Conversation
|
924ba10
to
3144f83
Compare
wondering if we should ship it in |
Seems to break valid tests that used to pass |
I was thinking the same 👍
So the problem is that e.g. |
That would be one option, but why does it fail? are those property different or is it due to things like different instances of functions? |
Handling concrete structures in the matcher would be perfect, we can support the full set of types in the library and it would become way easier to compare them. Wondering if those should be tight to vitest though, probably jest and other frameworks have the same issue |
Yes, they are different because the check compares an instance produced by some flow doing modifications (results in none-zero import { HashMap } from 'effect';
const hm1 = HashMap.fromIterable([[1, 1]]);
const hm2 = HashMap.empty<number, number>().pipe(HashMap.set(1, 1));
console.log(hm1._edit, hm2._edit); // 0 1 |
I pushed a draft of a potential solution based on equivalences. I wanted to reuse some kind of equality that's already present in the codebase and I need a way for the vitest's equality fn to take control in certain places. So it felt like a natural solution. The final outcome is a new function in the @effect/vitest that extends the custom testers which can be used in the user-land to extend the ability of vitest matchers to compare effect's data structures. Please let me know whether you think this is the way to go. |
611441b
to
dd75e67
Compare
Why not equals? Equivalence is usually explicit between known types |
Because equals says two things are equal only if they are strictly equal or when they implement the |
Also, the idea behind the |
bc6b100
to
12a22ec
Compare
12a22ec
to
d47e9de
Compare
I wonder whether it makes sense to deal with a non-strict equality for keys in hashmaps. They are implemented using a hash function which generates a random number for objects so it is non-sensical to use anything other than strictly comparable types as keys (or values that equal by reference). If I wanted to provide the equivalence implementation with an expectation the key can be of any type and the equivalence would be used instead of a strict equal, it wouldn't be possible to have ~O(n) implementation. Also |
HashMap keys are not using strict equality they are using Equals, random hash is for mutable objects, by default objects are mutable but they can implement the Equal trait and customize equality. Imho the only non weird default is to use equal, though I see the deep compare expectation |
Hey, I was playing around with the idea of fallbacking to |
Addressing the bug in Cause equality: #2653 |
Closing as #2653 seems to work fine and doesn't need specificity for data types |
Temporary fix for vitest-dev/vitest#5620 as right now the tests comparing objects with effect prototype will always succeed. Can be removed once fixed in the vitest.