-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Question: global option for Promise implementation to use? #1389
Comments
I am not opposed to making changes to accommodate per-instance configuration. The proposed changes will lead to a new Here's what I am thinking: currently So something like this? const Bluebird = require('bluebird');
const sinon = require('sinon')({ promiseImplementation: Bluebird}); What do you think? Ping @sinonjs/core |
I think @mroderick's idea to change the Sinon object into a function is great. Having a place to pass configs into a Sinon instance will sure be useful in the future, not only for promise configuration. However, I think this can be done in a backward compatible way by setting all the current Sinon object properties on the function. I would like to keep the current "stateless" nature and not force everybody to do |
Another option would be to expose a factory function on the sinon object; ie: const mySinon = sinon.withConfig({ promiseImplementation: Bluebird }); |
That was what I was thinking, but failed to express. To follow SemVer, we will still need to publish a new I am slightly more in favour of changing the export to a factory |
I have no hard feelings on either solution. @mroderick I agree that changing the object to a function is a major release, but adding the factory function is a minor, right? Wanted to add a label 🏷 |
@mantoni that is my understanding too |
Hi, friends, I was working on this a bit yesterday and I came up with a few moments of indecision and I'd like to explain my thoughts to you so you can approve what I'm doing before I submit a PR.
Also, do we plan on returning a new Sinon instance whenever we call |
+1 for this feature. I'm running some issues trying to use bluebird + sinon 1 + sinon-as-promised latest versions with an error about:
That is because Sinon 2 has no resolves, as sinon 2 supports native promises. |
Copying from pull request #1542 to keep everything in one place: fatso83:
druotic:
|
@lucasfcosta I would really like to land this to avoid bumping the major version twice in short succession (due to #1557), so if you have code to support a configurable Sinon instance, I think a PR would be most welcome. As I saw there was a bit of confusion, I'll touch on most of your points below. As to 1 (regarding state), yes, we would have to pass in a config object to the various functions in order to support different instances of sinon, and this requires a bit of change in the underlying modules. Not a lot, though, as the amount of config that can be changed today pretty much amounts to
I think the clearest option here is to return a new instance for each config, but perhaps caching the default instance, as it will probably be used in most cases. It's up to the clients to cache the instance of they feel they need to (say, as an export in Another thing, is that from the discussion above, I think we landed on making
|
P.S. We might consider moving the discussion to a separate issue, as this one deals with something entirely different, although dependent on the discussed change being present. |
@mroderick Regarding the factory that would be attached to the So I just would use const mySinon = sinon.create(config); This is much more intuitive than introducing a different factory function name here. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Question:
Sinon 2.2.0 introduces
stub.usingPromise()
, which let's one use a custom Promise implementation on a per-stub basis. This is great, thanks for that! 🎉My question is: what do you think about providing a global configuration option (e.g. per test file) for specifying a custom Promise implementation?
For example, similar to how
sinon-as-promised
did it back in the old days: https://github.com/bendrucker/sinon-as-promised#usageThe text was updated successfully, but these errors were encountered: