question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Context proxying doesn't work with Date

See original GitHub issue

Not sure the reason, stepped through the code briefly. Something like this doesn’t work:

test('whatever', context => {
  let { date } = context;

  date.getTime(); // throws.
});

I think getTime() doesn’t like it when the receiver is a proxy.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
lukeedcommented, Oct 13, 2020

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 😉

1reaction
lukeedcommented, Oct 13, 2020

@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, Object.create(context) doesn’t work because (as you’ve pointed out) the context is mounted as a prototype. Any changes (to existing keys) on the Object.create would affect the original context, at which point there’s no immutability protection. That kinda defeats the purpose IMO since the point of context is to pass around shared values – if those are still vulnerable – and only new keys got washed away after each test – then there’s no real point in Object.createing at all. I would be just as well off using local variables inside my test.

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 klona is doing, and while it’s currently the fastest of the deep-cloners, including it in a place like before.each would still have some measurable impact on test runtime. Here’s a hodgepodge of a few different metrics – also included plain object creators (pojo, nCreate, oCreate) just to illustrate the cost between them.

While it may be obvious, an important, unrelated callout is that if you ever see Object.create({}), replace that with {} or Object.create(Object.prototype) for free performance boost. We’re talking 2B vs 2M ops/sec~!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proxy on a date object - javascript - Stack Overflow
My original answer was all wrong. But the following handler should work. const handler = { get: function(target, name) { return name in ......
Read more >
Configure your proxy or firewall to enable Microsoft Defender ...
Describes how to set up your firewall or proxy to allow communication between the Microsoft Defender for Identity cloud service and ...
Read more >
Set up Lambda proxy integrations in API Gateway
Learn how to configure a Lambda proxy integration request and integration response in API Gateway.
Read more >
What is a Proxy Server and How Does it Work? - Varonis
A proxy server acts as a gateway between you and the internet. Learn the basics about proxies with our complete, easy-to-follow guide.
Read more >
Configuring Proxies for Tableau Server
Confirm that the proxy settings do not conflict with other Windows proxy configurations. Step 6: Test the proxy configuration. To test the new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found