Merge chai-as-promised into core, as Promise now are widely used. #882

Open
lygstate opened this Issue Dec 11, 2016 · 4 comments

Projects

None yet

3 participants

@lygstate

No description provided.

@lucasfcosta
Member

Hi @lygstate, thanks for your issue, this does make total sense.

Maybe we could do this as we did with chai-change, but first we'd need to talk to the whole team and specially with @domenic, which is chai-as-promised author (and did an awesome job with it BTW).

Personally I feel like the tendency of any plugin or library that gets widely used is to become part of the core and this does not happen only with Chai. A clear example for that is what happened with jQuery's selectors and document.querySelector.

Anyway, let's wait to hear from everyone before taking a decision.

@astorije
Member

I agree that this makes a lot of sense indeed, but there is something to take into account here.

Since chai-as-promised works by overriding available assertions, plugins will be affected.

For example, chai-immutable works by overriding assertions so that when evaluating an Immutable structure, the plugin gets used, otherwise it defaults to the existing assertions.
To be compatible with chai-as-promised, plugins overriding methods need to be loaded before chai-as-promised, as explained here (see astorije/chai-immutable#32).

While I'd personally be happy to see chai-as-promised in the main project, and apply necessary fixes to chai-immutable accordingly, this would break existing plugins and require updating documentations of the override*(...) plugin utilities.

@lucasfcosta
Member

Thanks for the warning, @astorije.

Wouldn't it be possible to make sure we "reloaded" chai-as-promised after each time someone called the use method?

Maybe we could keep track of the methods being added whenever someone calls any of the add*(...) or overwrite(...) methods and then override those again with our internal implementation of chai-as-promised in order to guarantee they would also be overwritten.

I didn't do much exploring on chai-as-promised's code, so let me know if I said anything wrong/impossible.

@astorije
Member

I'm not sure about wrong/impossible as I am not an expert with chai-as-promised code, we'd need @domenic to chime in :)

However, I'm seeing a potential issue if some plugins expect to run after chai-as-promised or any plugin that affects existing assertions. I'm thinking about plugins like https://github.com/prodatakey/dirty-chai (odd that this plugin didn't appear in the plugins page, though I'm thinking this one will become unnecessary after v4).

I actually don't know chai-as-promised could be integrated as is in the repo. If I remember correctly, it works by adding a eventually flag then monkey-patching all assertions to support it. Merging it with the main project would instead implement support for eventually natively in assertions, and therefore require all plugins to do so as well. Either that or transform chai-as-promised into plugin-as-promised that monkey patches plugins only...
I don't know, I might be very wrong, I'm tired :) I'd love to hear @domenic's thoughts either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment