Enable Bluebird generator support in Mocha

Promise-yielding ES6 generator functions can now be used for test
functions, and they'll automatically be wrapped with Bluebird's
coroutine().
This commit is contained in:
Dan Stillman 2015-04-15 01:32:40 -04:00
parent 384a547693
commit 973e602cfc
2 changed files with 15 additions and 2 deletions

View file

@ -66,6 +66,19 @@ function Reporter(runner) {
// Setup Mocha
mocha.setup({ui:"bdd", reporter:Reporter});
// Enable Bluebird generator support in Mocha
(function () {
var Runnable = Mocha.Runnable;
var run = Runnable.prototype.run;
Runnable.prototype.run = function (fn) {
if (this.fn.constructor.name === 'GeneratorFunction') {
this.fn = Zotero.Promise.coroutine(this.fn);
}
return run.call(this, fn);
};
})();
var assert = chai.assert,
expect = chai.expect;