acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
434 stars 46 forks source link

Set props and methods as enumerable and configurable #77

Closed tfoxy closed 6 years ago

tfoxy commented 6 years ago

When using the chrome API in the browser, the methods and props are enumerable:

Object.getOwnPropertyDescriptor(chrome.tabs, 'create')
// {writable: true, enumerable: true, configurable: true, value: function}

When using sinon-chrome, the methods and props are not enumerable

Object.getOwnPropertyDescriptor(chrome.tabs, 'create')
// {get: function, set: undefined, enumerable: false, configurable: false}

This PR creates methods, props and events as enumerable and configurable.

acvetkov commented 6 years ago

@tfoxy, hi. thx for pr.

For what reason do you need this feature?

tfoxy commented 6 years ago

I wrote a library called chrome-promise, where instead of using callbacks for the methods, you can use promises. In that library, all apis are added by iterating every property.

A few months ago, an issue was opened saying that sinon-chrome couldn't be used with the library: https://github.com/tfoxy/chrome-promise/issues/16 . In version 0.2.1 of sinon-chrome, properties are enumerable and it works with chrome-promise. After that version, there was a refactor where properties weren't enumerable anymore.

I think that having enumerable properties is better only because the chrome API also has enumerable properties.

acvetkov commented 6 years ago

@tfoxy hi.

Sorry for delay. I've published new version on sinon-chrome@2.3.2 with your patch. P.S. check out my chrome-promise lib :) https://github.com/acvetkov/then-chrome

tfoxy commented 6 years ago

Thanks! Yeah, I had seen it before. Yours have sync methods, which is great. A week ago someone contacted me to tell me that Mozilla also has a library for this:

https://github.com/mozilla/webextension-polyfill

As soon as I fix something on my repo, I will release a new version and in the readme I will mention both libraries. It's been a long time since the last time I developed a chrome extension, so I'm not really interested in maintaining it in the long run. So it's better if I can give people some alternatives.

acvetkov commented 6 years ago

So it's better if I can give people some alternatives.

👍