commit 973e602cfc9efb5a85f02f73a028bd700129e07e
parent 384a547693551ce3ac707a9fdf8432cbc59652cc
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 15 Apr 2015 01:32:40 -0400
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().
Diffstat:
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/test/content/runtests.js b/test/content/runtests.js
@@ -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;
diff --git a/test/tests/support.js b/test/tests/support.js
@@ -1,6 +1,6 @@
describe("Support Functions for Unit Testing", function() {
describe("resetDB", function() {
- it("should restore the DB to factory settings", Zotero.Promise.coroutine(function* () {
+ it("should restore the DB to factory settings", function* () {
this.timeout(30000);
yield Zotero.Items.erase(1);
assert.isFalse(yield Zotero.Items.getAsync(1));
@@ -9,6 +9,6 @@ describe("Support Functions for Unit Testing", function() {
assert.isObject(item);
yield item.loadItemData();
assert.equal(item.getField("url"), "https://www.zotero.org/support/quick_start_guide");
- }));
+ });
});
});