-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Context proxying doesn't work with Date #39
Comments
Thanks for this – it's been interesting to play with... 😅
Additionally, setting up that binding will make things like I'm still playing with it. Don't want to go down the detect-every-constructor route, because that list will be never ending, especially with custom classes. Looking at |
This just bit me too; I tried using Typed Arrays in context. Can't use My question is why do you need to prevent mutations in the context? Performance and compatibility dramatically increase by not using |
Yes, this is a possibility I'm considering. The initial idea was that preventing context mutation would unlock the ability for a suite's tests to be run in parallel (when the feature came). |
You could have the context object in the before() and just warn people that it's mutable, then in before.each have a separate context object that is |
Unfortunately that wouldn't be immutable – and from a performance standpoint, it'd be really expensive to // suite.before
let context = { foo: [1, 2, 3] };
// suite.before.each
let copy = Object.create(context);
// my test
copy.foo.push(1, 2, 3);
console.log(context.foo);
//=> [1, 2, 3, 1, 2, 3] |
Yeah, I meant that properties you add to the context in the before.each are immutable. If you mutate the proto you are mutating the before context and that is of course shared. In my experience most before type things you want to do can be done in a before.each and that should be the preferred place to do them. |
Just to add in, import { test } from 'uvu';
test.before((context) => {
context.map = new Map();
context.set = new Set();
});
test('map.entries()', ({ map }) => {
map.entries();
});
test('set.values()', ({ set }) => {
set.values();
}); |
Ya I'll probably have to drop the immutability locker. Was a nice idea but doesn't seem to be all that viable (sans cloning objects before each test). If you consider this a must-have, please say so now before it's too late 😉 |
@lukeed It's cool if you don't like the Object.create() idea but just to be clear it's not a copy or a clone. Creating an object is not O(n), it's equivalent to the cost of creating a new object in a function which is something people do constantly. I'd be very surprised if you could create a benchmark, even a really unrealistic one, that could show a perf cost to this. This is just Again, happy with whatever decision you prefer, just felt the need to defend prototypes a bit 😀 |
@matthewp I wasn't talking about Object.create in my last comment :) Yes it's a new object, but as demonstrated in my snippet above, Creating a new object and then assigning the keys to that object would then be a copy/clone, and that's where the performance question comes in. This is what
|
Not sure the reason, stepped through the code briefly. Something like this doesn't work:
I think
getTime()
doesn't like it when the receiver is a proxy.The text was updated successfully, but these errors were encountered: