Comparing version 1.2.0 to 1.2.1
@@ -5,2 +5,14 @@ # Change Log | ||
## [1.2.0](https://github.com/blakeembrey/co-mocha/compare/v1.1.3...v1.2.0) - 2017-01-24 | ||
### Changed | ||
- Check `exports.name` when auto-hooking Mocha instead of matching path name (for alternative NPM clients that link) | ||
## [1.1.3](https://github.com/blakeembrey/co-mocha/compare/v1.1.2...v1.1.3) - 2016-08-01 | ||
### Changed | ||
- Update Mocha `peerDependency` version range | ||
## [1.1.2](https://github.com/blakeembrey/co-mocha/compare/v1.1.1...v1.1.2) - 2015-06-17 | ||
@@ -7,0 +19,0 @@ |
124
co-mocha.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.coMocha = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var co = require('co') | ||
var path = require('path') | ||
var isGenFn = require('is-generator').fn | ||
@@ -56,3 +55,2 @@ | ||
function findNodeJSMocha () { | ||
var suffix = path.sep + path.join('', 'mocha', 'index.js') | ||
var children = require.cache || {} | ||
@@ -62,3 +60,4 @@ | ||
.filter(function (child) { | ||
return child.slice(suffix.length * -1) === suffix | ||
var val = children[child].exports | ||
return typeof val === 'function' && val.name === 'Mocha' | ||
}) | ||
@@ -75,6 +74,4 @@ .map(function (child) { | ||
},{"co":3,"is-generator":4,"path":2}],2:[function(require,module,exports){ | ||
},{"co":2,"is-generator":3}],2:[function(require,module,exports){ | ||
},{}],3:[function(require,module,exports){ | ||
/** | ||
@@ -90,3 +87,3 @@ * slice() reference. | ||
module.exports = co; | ||
module.exports = co['default'] = co.co = co; | ||
@@ -106,5 +103,7 @@ /** | ||
co.wrap = function (fn) { | ||
return function () { | ||
createPromise.__generatorFunction__ = fn; | ||
return createPromise; | ||
function createPromise() { | ||
return co.call(this, fn.apply(this, arguments)); | ||
}; | ||
} | ||
}; | ||
@@ -117,3 +116,3 @@ | ||
* @param {Function} fn | ||
* @return {Function} | ||
* @return {Promise} | ||
* @api public | ||
@@ -124,53 +123,62 @@ */ | ||
var ctx = this; | ||
if (typeof gen === 'function') gen = gen.call(this); | ||
return onFulfilled(); | ||
var args = slice.call(arguments, 1) | ||
/** | ||
* @param {Mixed} res | ||
* @return {Promise} | ||
* @api private | ||
*/ | ||
// we wrap everything in a promise to avoid promise chaining, | ||
// which leads to memory leak errors. | ||
// see https://github.com/tj/co/issues/180 | ||
return new Promise(function(resolve, reject) { | ||
if (typeof gen === 'function') gen = gen.apply(ctx, args); | ||
if (!gen || typeof gen.next !== 'function') return resolve(gen); | ||
function onFulfilled(res) { | ||
var ret; | ||
try { | ||
ret = gen.next(res); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
onFulfilled(); | ||
/** | ||
* @param {Mixed} res | ||
* @return {Promise} | ||
* @api private | ||
*/ | ||
function onFulfilled(res) { | ||
var ret; | ||
try { | ||
ret = gen.next(res); | ||
} catch (e) { | ||
return reject(e); | ||
} | ||
next(ret); | ||
} | ||
return next(ret); | ||
} | ||
/** | ||
* @param {Error} err | ||
* @return {Promise} | ||
* @api private | ||
*/ | ||
/** | ||
* @param {Error} err | ||
* @return {Promise} | ||
* @api private | ||
*/ | ||
function onRejected(err) { | ||
var ret; | ||
try { | ||
ret = gen.throw(err); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
function onRejected(err) { | ||
var ret; | ||
try { | ||
ret = gen.throw(err); | ||
} catch (e) { | ||
return reject(e); | ||
} | ||
next(ret); | ||
} | ||
return next(ret); | ||
} | ||
/** | ||
* Get the next value in the generator, | ||
* return a promise. | ||
* | ||
* @param {Object} ret | ||
* @return {Promise} | ||
* @api private | ||
*/ | ||
/** | ||
* Get the next value in the generator, | ||
* return a promise. | ||
* | ||
* @param {Object} ret | ||
* @return {Promise} | ||
* @api private | ||
*/ | ||
function next(ret) { | ||
if (ret.done) return Promise.resolve(ret.value); | ||
var value = toPromise.call(ctx, ret.value); | ||
if (value && isPromise(value)) return value.then(onFulfilled, onRejected); | ||
return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, ' | ||
+ 'but the following object was passed: "' + String(ret.value) + '"')); | ||
} | ||
function next(ret) { | ||
if (ret.done) return resolve(ret.value); | ||
var value = toPromise.call(ctx, ret.value); | ||
if (value && isPromise(value)) return value.then(onFulfilled, onRejected); | ||
return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, ' | ||
+ 'but the following object was passed: "' + String(ret.value) + '"')); | ||
} | ||
}); | ||
} | ||
@@ -291,6 +299,7 @@ | ||
*/ | ||
function isGeneratorFunction(obj) { | ||
var constructor = obj.constructor; | ||
return constructor && 'GeneratorFunction' == constructor.name; | ||
if (!constructor) return false; | ||
if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true; | ||
return isGenerator(constructor.prototype); | ||
} | ||
@@ -310,3 +319,3 @@ | ||
},{}],4:[function(require,module,exports){ | ||
},{}],3:[function(require,module,exports){ | ||
/** | ||
@@ -339,4 +348,3 @@ * Export generator function checks. | ||
fn.constructor && | ||
fn.constructor.name === 'GeneratorFunction' && | ||
isGenerator(fn.prototype) | ||
fn.constructor.name === 'GeneratorFunction' | ||
} | ||
@@ -343,0 +351,0 @@ |
var co = require('co') | ||
var path = require('path') | ||
var isGenFn = require('is-generator').fn | ||
@@ -55,3 +54,2 @@ | ||
function findNodeJSMocha () { | ||
var suffix = path.sep + path.join('', 'mocha', 'index.js') | ||
var children = require.cache || {} | ||
@@ -58,0 +56,0 @@ |
{ | ||
"name": "co-mocha", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Enable support for generators in Mocha tests", | ||
@@ -11,5 +11,2 @@ "main": "lib/co-mocha.js", | ||
], | ||
"browser": { | ||
"path": false | ||
}, | ||
"scripts": { | ||
@@ -20,3 +17,3 @@ "lint": "standard", | ||
"test-cov": "testem ci -l Firefox,Node", | ||
"test": "npm run lint && npm run build && npm run test-cov" | ||
"test": "mocha -V && npm run lint && npm run build && npm run test-cov" | ||
}, | ||
@@ -45,9 +42,8 @@ "repository": { | ||
"browserify": "^14.0.0", | ||
"chai": "^3.0.0", | ||
"chai": "^4.0.1", | ||
"es6-promise": "^4.0.5", | ||
"istanbul": "git://github.com/gotwarlost/istanbul#harmony", | ||
"mocha": "^3.1.2", | ||
"pre-commit": "^1.0.7", | ||
"regenerator": "^0.9.0", | ||
"standard": "^8.5.0", | ||
"istanbul": "^1.1.0-alpha.1", | ||
"mocha": "*", | ||
"regenerator": "^0.10.0", | ||
"standard": "^10.0.0", | ||
"testem": "^1.13.0", | ||
@@ -69,4 +65,4 @@ "traceur": "0.0.111" | ||
"peerDependencies": { | ||
"mocha": ">=1.18 <4" | ||
"mocha": ">=1.18 <5" | ||
} | ||
} |
@@ -7,2 +7,3 @@ # Co Mocha | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[](https://greenkeeper.io/) | ||
@@ -9,0 +10,0 @@ Enable support for generators in Mocha tests using [co](https://github.com/visionmedia/co). |
17862
9
353
70