Support generators in tests via coMocha, instead of custom code

* coMocha offers better error stack trace
This commit is contained in:
Tom Najdek 2017-05-31 16:30:56 +01:00 committed by Dan Stillman
parent 14bf3184bb
commit 289b049377
5 changed files with 6 additions and 14 deletions

View File

@ -11,7 +11,8 @@
"resource/react-dom.js", "resource/react-dom.js",
"resource/bluebird.js", "resource/bluebird.js",
"test/resource/httpd.js", "test/resource/httpd.js",
"test/resource/mocha.js" "test/resource/mocha.js",
"test/resource/co-mocha.js"
], ],
"plugins": [ "plugins": [
"syntax-flow", "syntax-flow",

View File

@ -33,6 +33,7 @@
"browserify": "^14.3.0", "browserify": "^14.3.0",
"chai": "^3.5.0", "chai": "^3.5.0",
"chai-as-promised": "^6.0.0", "chai-as-promised": "^6.0.0",
"co-mocha": "^1.2.0",
"del": "^2.2.2", "del": "^2.2.2",
"glob": "^7.1.2", "glob": "^7.1.2",
"gulp": "^3.9.1", "gulp": "^3.9.1",

View File

@ -9,6 +9,7 @@
<script src="resource://zotero-unit/chai.js"></script> <script src="resource://zotero-unit/chai.js"></script>
<script src="resource://zotero-unit/chai-as-promised.js"></script> <script src="resource://zotero-unit/chai-as-promised.js"></script>
<script src="resource://zotero-unit/mocha.js"></script> <script src="resource://zotero-unit/mocha.js"></script>
<script src="resource://zotero-unit/co-mocha.js"></script>
<script src="resource://zotero-unit/sinon.js"></script> <script src="resource://zotero-unit/sinon.js"></script>
<script src="resource://zotero-unit/pako_inflate.js"></script> <script src="resource://zotero-unit/pako_inflate.js"></script>
<script src="support.js" type="application/javascript;version=1.8"></script> <script src="support.js" type="application/javascript;version=1.8"></script>

View File

@ -184,19 +184,7 @@ mocha.setup({
grep: ZoteroUnit.grep grep: ZoteroUnit.grep
}); });
// Enable Bluebird generator support in Mocha coMocha(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);
} else if (typeof this.fn == 'function' && this.fn.isGenerator()) {
throw new Error("Attempting to use a legacy generator in Mocha test");
}
return run.call(this, fn);
};
})();
before(function () { before(function () {
// Store all prefs set in runtests.sh // Store all prefs set in runtests.sh

1
test/resource/co-mocha.js Symbolic link
View File

@ -0,0 +1 @@
../../node_modules/co-mocha/co-mocha.js