emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.47k stars 4.21k forks source link

Using sinon triggers deprecation warnings in tests. #17046

Open Gaurav0 opened 6 years ago

Gaurav0 commented 6 years ago

See reproduction (open console): https://ember-twiddle.com/969a3d23d9ef9b6ae643cff85cb07183?openFiles=twiddle.json%2C

sinon enumerates objects and thus finds and accesses deprecated properties, causing deprecation warnings in tests.

pixelhandler commented 6 years ago

@Gaurav0 yeah I see this in the console:

DEPRECATION: Getting the '@each' property on object  is deprecated [deprecation id: ember-metal.getting-each] See https://emberjs.com/deprecations/v3.x#toc_getting-the-each-property for more details.

And when I remove sinon as a dependency the deprecation is gone.

sukima commented 5 years ago

Confirmed. I see this in my apps as well. Is there a workaround?

Can a deprecated property like @each be enumerable: false?

backspace commented 5 years ago

Thanks for opening this, I’m finding this too while working on fixing deprecations while updating travis-web to 3.6. I was surprised that the documentation says it’ll be removed in Ember 3.5 as we’re already on that version! 😯

runspired commented 5 years ago

So roughly the issue here is that sinon wraps the modules and tries to clone the prototypes of each property of default exports in order to prepare for stubbing. That in turn results in the following call that iterates ownPropertyNames which accesses the "deprecated setter" for @each when wrapping that module.

return Object.getOwnPropertyNames(u).reduce(function(l, n) {
                    return "size" !== n && "caller" !== n && "callee" !== n && "arguments" !== n && "function" == typeof u[n] && (l[n] = e.bind(u[n])),
                    l
                }, Object.create(null))
sukima commented 5 years ago

In other words, either @each needs to be configured enumerable: false (invasive)

OR

Ignore the deprecation warning and it will go away once @each is removed (passive).

rwjblue commented 5 years ago

I think that https://github.com/emberjs/ember.js/issues/17190#issuecomment-440717625 is the same issue here.

This seems like a regression of the fixes in https://github.com/emberjs/ember.js/pull/16169 which was specifically trying to address this issue...