├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bower.json ├── co-mocha.js ├── lib └── co-mocha.js ├── package.json ├── test.js └── testem.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | coverage 4 | .idea 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | 4 | notifications: 5 | email: 6 | on_success: never 7 | on_failure: change 8 | 9 | before_install: 10 | - "export DISPLAY=:99.0" 11 | - "sh -e /etc/init.d/xvfb start" 12 | - npm install $MOCHA --force 13 | 14 | env: 15 | - MOCHA=mocha@1 16 | - MOCHA=mocha@2 17 | - MOCHA=mocha@3 18 | - MOCHA=mocha@4 19 | - MOCHA=mocha@5 20 | 21 | node_js: 22 | - "0.10" 23 | - "4" 24 | - "stable" 25 | 26 | matrix: 27 | exclude: 28 | - env: MOCHA=mocha@4 29 | node_js: "0.10" 30 | - env: MOCHA=mocha@5 31 | node_js: "0.10" 32 | 33 | after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" 34 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## [1.2.1](https://github.com/blakeembrey/co-mocha/compare/v1.2.0...v1.2.1) - 2017-10-11 6 | 7 | ### Changed 8 | 9 | - Add mocha v4 to version range 10 | 11 | ## [1.2.0](https://github.com/blakeembrey/co-mocha/compare/v1.1.3...v1.2.0) - 2017-01-24 12 | 13 | ### Changed 14 | 15 | - Check `exports.name` when auto-hooking Mocha instead of matching path name (for alternative NPM clients that link) 16 | 17 | ## [1.1.3](https://github.com/blakeembrey/co-mocha/compare/v1.1.2...v1.1.3) - 2016-08-01 18 | 19 | ### Changed 20 | 21 | - Update Mocha `peerDependency` version range 22 | 23 | ## [1.1.2](https://github.com/blakeembrey/co-mocha/compare/v1.1.1...v1.1.2) - 2015-06-17 24 | 25 | ### Changed 26 | 27 | - Wrap `this.fn.toString` in a custom function to support the HTML reporter with function bodies. 28 | 29 | ### Added 30 | 31 | - Created a project CHANGELOG. 32 | 33 | ## [1.1.1](https://github.com/blakeembrey/co-mocha/compare/v1.1.0...v1.1.1) - 2015-06-16 34 | 35 | ### Changed 36 | 37 | - Update to latest dev dependencies. 38 | - Use `--harmony` flag for `iojs` support in CI. 39 | - Update to `standard` module format and syntax. 40 | 41 | ### Added 42 | 43 | - Use `pre-commit` for testing. 44 | - Add node `0.12` and `iojs` to Travis CI. 45 | - Support for browsers. 46 | - Add instructions for monkey patching Mocha manually to README. 47 | - Add tests for browsers on Travis CI. 48 | 49 | ### Removed 50 | 51 | - Remove `bluebird` dependency and use native promises. 52 | 53 | ## [1.1.0](https://github.com/blakeembrey/co-mocha/compare/v1.0.3...v1.1.0) - 2014-11-18 54 | 55 | ### Changed 56 | 57 | - Update to `co@4.x`. 58 | 59 | ## [1.0.3](https://github.com/blakeembrey/co-mocha/compare/v1.0.2...v1.0.3) - 2014-10-29 60 | 61 | ### Changed 62 | 63 | - Use `require.cache` instance of main script children. 64 | 65 | ## [1.0.2](https://github.com/blakeembrey/co-mocha/compare/v1.0.1...v1.0.2) - 2014-10-22 66 | 67 | ### Changed 68 | 69 | - Update Mocha peer dependency to support Mocha 2.x. 70 | 71 | ## [1.0.1](https://github.com/blakeembrey/co-mocha/compare/v1.0.0...v1.0.1) - 2014-09-02 72 | 73 | ### Changed 74 | 75 | - Simplified code back to the original release snippet. 76 | 77 | ## [1.0.0](https://github.com/blakeembrey/co-mocha/compare/v0.0.4...v1.0.0) - 2014-08-18 78 | 79 | ### Changed 80 | 81 | - Switch to using promises internally. 82 | - Refactor generator tests to work as expected. 83 | - Update dependencies. 84 | - Update author information. 85 | 86 | ### Added 87 | 88 | - Add Travis CI. 89 | - Add badges to README. 90 | - Add code coverage information. 91 | 92 | ## [0.0.4](https://github.com/blakeembrey/co-mocha/compare/v0.0.3...v0.0.4) - 2014-05-06 93 | 94 | ### Fixed 95 | 96 | - Correctly pass context for test functions. 97 | 98 | ## [0.0.3](https://github.com/blakeembrey/co-mocha/compare/v0.0.2...v0.0.3) - 2014-05-05 99 | 100 | ### Added 101 | 102 | - Add support for ES6 transpilers. 103 | - Find and monkey patch any available Mocha module loaded under node main. 104 | 105 | ## [0.0.2](https://github.com/blakeembrey/co-mocha/compare/v0.0.1...v0.0.2) - 2014-03-04 106 | 107 | ### Added 108 | 109 | - Released on NPM under `co-mocha`. 110 | - Simple example in README. 111 | 112 | ## 0.0.1 - 2014-02-04 113 | 114 | ### Added 115 | 116 | - Initial release based on blog post for testing using generator functions. 117 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Co Mocha 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![NPM downloads][downloads-image]][downloads-url] 5 | [![Build status][travis-image]][travis-url] 6 | [![Test coverage][coveralls-image]][coveralls-url] 7 | [![Greenkeeper badge](https://badges.greenkeeper.io/blakeembrey/co-mocha.svg)](https://greenkeeper.io/) 8 | 9 | Enable support for generators in Mocha tests using [co](https://github.com/visionmedia/co). 10 | 11 | Use the `--harmony-generators` flag when running node 0.11.x to access generator functions, or transpile your tests using [traceur](https://github.com/google/traceur-compiler) or [regenerator](https://github.com/facebook/regenerator). 12 | 13 | ## Installation 14 | 15 | ``` 16 | npm install co-mocha --save-dev 17 | ``` 18 | 19 | ## Usage 20 | 21 | Just require the module in your tests and start writing generators in your tests. 22 | 23 | ```js 24 | it('should do something', function * () { 25 | yield users.load(123) 26 | }) 27 | ``` 28 | 29 | ### Node 30 | 31 | Install the module using `npm install co-mocha --save-dev`. Now just require the module to automatically monkey patch any available `mocha` instances. With `mocha`, you have multiple ways of requiring the module - add `--require co-mocha` to your `mocha.opts` or add `require('co-mocha')` inside your main test file. 32 | 33 | If you need to monkey patch a different mocha instance you can use the library directly: 34 | 35 | ```js 36 | var mocha = require('mocha') 37 | var coMocha = require('co-mocha') 38 | 39 | coMocha(mocha) 40 | ``` 41 | 42 | ### ` 46 | ``` 47 | 48 | Including the browserified script will automatically patch `window.Mocha`. Just make sure you include it after `mocha.js`. If that is not possible the library exposes `window.coMocha`, which can be used (`window.coMocha(window.Mocha)`). 49 | 50 | ### AMD 51 | 52 | Same details as the script, but using AMD requires instead. 53 | 54 | ## How It Works 55 | 56 | The module monkey patches the `Runnable.prototype.run` method of `mocha` to enable generators. In contrast to other npm packages, `co-mocha` extends `mocha` at runtime - allowing you to use any compatible mocha version. 57 | 58 | ## License 59 | 60 | MIT 61 | 62 | [npm-image]: https://img.shields.io/npm/v/co-mocha.svg?style=flat 63 | [npm-url]: https://npmjs.org/package/co-mocha 64 | [downloads-image]: https://img.shields.io/npm/dm/co-mocha.svg?style=flat 65 | [downloads-url]: https://npmjs.org/package/co-mocha 66 | [travis-image]: https://img.shields.io/travis/blakeembrey/co-mocha.svg?style=flat 67 | [travis-url]: https://travis-ci.org/blakeembrey/co-mocha 68 | [coveralls-image]: https://img.shields.io/coveralls/blakeembrey/co-mocha.svg?style=flat 69 | [coveralls-url]: https://coveralls.io/r/blakeembrey/co-mocha?branch=master 70 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "co-mocha", 3 | "main": "co-mocha.js", 4 | "version": "1.2.1", 5 | "homepage": "https://github.com/blakeembrey/co-mocha", 6 | "authors": [ 7 | "Blake Embrey " 8 | ], 9 | "description": "Enable support for generators in Mocha tests", 10 | "keywords": [ 11 | "co", 12 | "mocha", 13 | "generators", 14 | "harmony", 15 | "tests" 16 | ], 17 | "license": "MIT", 18 | "ignore": [ 19 | "**/.*", 20 | "lib", 21 | "node_modules", 22 | "bower_components", 23 | "test.js" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /co-mocha.js: -------------------------------------------------------------------------------- 1 | (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(){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 2) res = slice.call(arguments, 1); 211 | resolve(res); 212 | }); 213 | }); 214 | } 215 | 216 | /** 217 | * Convert an array of "yieldables" to a promise. 218 | * Uses `Promise.all()` internally. 219 | * 220 | * @param {Array} obj 221 | * @return {Promise} 222 | * @api private 223 | */ 224 | 225 | function arrayToPromise(obj) { 226 | return Promise.all(obj.map(toPromise, this)); 227 | } 228 | 229 | /** 230 | * Convert an object of "yieldables" to a promise. 231 | * Uses `Promise.all()` internally. 232 | * 233 | * @param {Object} obj 234 | * @return {Promise} 235 | * @api private 236 | */ 237 | 238 | function objectToPromise(obj){ 239 | var results = new obj.constructor(); 240 | var keys = Object.keys(obj); 241 | var promises = []; 242 | for (var i = 0; i < keys.length; i++) { 243 | var key = keys[i]; 244 | var promise = toPromise.call(this, obj[key]); 245 | if (promise && isPromise(promise)) defer(promise, key); 246 | else results[key] = obj[key]; 247 | } 248 | return Promise.all(promises).then(function () { 249 | return results; 250 | }); 251 | 252 | function defer(promise, key) { 253 | // predefine the key in the result 254 | results[key] = undefined; 255 | promises.push(promise.then(function (res) { 256 | results[key] = res; 257 | })); 258 | } 259 | } 260 | 261 | /** 262 | * Check if `obj` is a promise. 263 | * 264 | * @param {Object} obj 265 | * @return {Boolean} 266 | * @api private 267 | */ 268 | 269 | function isPromise(obj) { 270 | return 'function' == typeof obj.then; 271 | } 272 | 273 | /** 274 | * Check if `obj` is a generator. 275 | * 276 | * @param {Mixed} obj 277 | * @return {Boolean} 278 | * @api private 279 | */ 280 | 281 | function isGenerator(obj) { 282 | return 'function' == typeof obj.next && 'function' == typeof obj.throw; 283 | } 284 | 285 | /** 286 | * Check if `obj` is a generator function. 287 | * 288 | * @param {Mixed} obj 289 | * @return {Boolean} 290 | * @api private 291 | */ 292 | function isGeneratorFunction(obj) { 293 | var constructor = obj.constructor; 294 | if (!constructor) return false; 295 | if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true; 296 | return isGenerator(constructor.prototype); 297 | } 298 | 299 | /** 300 | * Check for plain object. 301 | * 302 | * @param {Mixed} val 303 | * @return {Boolean} 304 | * @api private 305 | */ 306 | 307 | function isObject(val) { 308 | return Object == val.constructor; 309 | } 310 | 311 | },{}],3:[function(require,module,exports){ 312 | /** 313 | * Export generator function checks. 314 | */ 315 | module.exports = isGenerator 316 | module.exports.fn = isGeneratorFunction 317 | 318 | /** 319 | * Check whether an object is a generator. 320 | * 321 | * @param {Object} obj 322 | * @return {Boolean} 323 | */ 324 | function isGenerator (obj) { 325 | return obj && 326 | typeof obj.next === 'function' && 327 | typeof obj.throw === 'function' 328 | } 329 | 330 | /** 331 | * Check whether a function is generator. 332 | * 333 | * @param {Function} fn 334 | * @return {Boolean} 335 | */ 336 | function isGeneratorFunction (fn) { 337 | return typeof fn === 'function' && 338 | fn.constructor && 339 | fn.constructor.name === 'GeneratorFunction' 340 | } 341 | 342 | },{}]},{},[1])(1) 343 | }); -------------------------------------------------------------------------------- /lib/co-mocha.js: -------------------------------------------------------------------------------- 1 | var co = require('co') 2 | var isGenFn = require('is-generator').fn 3 | 4 | /** 5 | * Export `co-mocha`. 6 | */ 7 | module.exports = coMocha 8 | 9 | /** 10 | * Monkey patch the mocha instance with generator support. 11 | * 12 | * @param {Function} mocha 13 | */ 14 | function coMocha (mocha) { 15 | // Avoid loading `co-mocha` twice. 16 | if (!mocha || mocha._coMochaIsLoaded) { 17 | return 18 | } 19 | 20 | var Runnable = mocha.Runnable 21 | var run = Runnable.prototype.run 22 | 23 | /** 24 | * Override the Mocha function runner and enable generator support with co. 25 | * 26 | * @param {Function} fn 27 | */ 28 | Runnable.prototype.run = function (fn) { 29 | var oldFn = this.fn 30 | 31 | if (isGenFn(oldFn)) { 32 | this.fn = co.wrap(oldFn) 33 | 34 | // Replace `toString` to output the original function contents. 35 | this.fn.toString = function () { 36 | // https://github.com/mochajs/mocha/blob/7493bca76662318183e55294e906a4107433e20e/lib/utils.js#L251 37 | return Function.prototype.toString.call(oldFn) 38 | .replace(/^function *\* *\(.*\)\s*{/, 'function () {') 39 | } 40 | } 41 | 42 | return run.call(this, fn) 43 | } 44 | 45 | mocha._coMochaIsLoaded = true 46 | } 47 | 48 | /** 49 | * Find active node mocha instances. 50 | * 51 | * @return {Array} 52 | */ 53 | function findNodeJSMocha () { 54 | var children = require.cache || {} 55 | 56 | return Object.keys(children) 57 | .filter(function (child) { 58 | var val = children[child].exports 59 | return typeof val === 'function' && val.name === 'Mocha' 60 | }) 61 | .map(function (child) { 62 | return children[child].exports 63 | }) 64 | } 65 | 66 | // Attempt to automatically monkey patch available mocha instances. 67 | var modules = typeof window === 'undefined' ? findNodeJSMocha() : [window.Mocha] 68 | 69 | modules.forEach(coMocha) 70 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "co-mocha", 3 | "version": "1.2.2", 4 | "description": "Enable support for generators in Mocha tests", 5 | "main": "lib/co-mocha.js", 6 | "files": [ 7 | "co-mocha.js", 8 | "lib/", 9 | "LICENSE" 10 | ], 11 | "scripts": { 12 | "lint": "standard", 13 | "build": "browserify lib/co-mocha.js -s co-mocha -o co-mocha.js", 14 | "test-spec": "mocha --harmony -R spec --require lib/co-mocha.js --bail", 15 | "test-cov": "testem ci -l Firefox,Node", 16 | "test": "mocha -V && npm run lint && npm run build && npm run test-cov" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git://github.com/blakeembrey/co-mocha.git" 21 | }, 22 | "keywords": [ 23 | "co", 24 | "mocha", 25 | "harmony", 26 | "generators" 27 | ], 28 | "author": { 29 | "name": "Blake Embrey", 30 | "email": "hello@blakeembrey.com", 31 | "url": "http://blakeembrey.me" 32 | }, 33 | "license": "MIT", 34 | "bugs": { 35 | "url": "https://github.com/blakeembrey/co-mocha/issues" 36 | }, 37 | "homepage": "https://github.com/blakeembrey/co-mocha", 38 | "devDependencies": { 39 | "browserify": "^14.0.0", 40 | "chai": "^4.0.1", 41 | "es6-promise": "^4.0.5", 42 | "istanbul": "^1.1.0-alpha.1", 43 | "mocha": "*", 44 | "regenerator": "^0.10.0", 45 | "standard": "^10.0.0", 46 | "testem": "^1.13.0", 47 | "traceur": "0.0.111" 48 | }, 49 | "standard": { 50 | "ignore": [ 51 | "coverage/**", 52 | "node_modules/**", 53 | "bower_components/**", 54 | "co-mocha.js" 55 | ] 56 | }, 57 | "dependencies": { 58 | "co": "^4.0.0", 59 | "is-generator": "^1.0.1" 60 | }, 61 | "peerDependencies": { 62 | "mocha": ">=1.18 <6" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-eval */ 2 | /* global describe, it, chai, ES6Promise */ 3 | 4 | var assert 5 | var Runnable 6 | var isNode = typeof require === 'function' 7 | 8 | if (isNode) { 9 | assert = require('chai').assert 10 | Runnable = require('mocha').Runnable 11 | } else { 12 | assert = chai.assert 13 | Runnable = window.Mocha.Runnable 14 | 15 | ES6Promise.polyfill() 16 | } 17 | 18 | /** 19 | * Thunkify a function for `process.nextTick`. 20 | * 21 | * @return {Function} 22 | */ 23 | function defer () { 24 | return new Promise(function (resolve) { 25 | setTimeout(resolve, 0) 26 | }) 27 | } 28 | 29 | describe('co-mocha', function () { 30 | describe('synchronous', function () { 31 | it('should pass', function (done) { 32 | var test = new Runnable('synchronous', function () {}) 33 | 34 | test.run(done) 35 | }) 36 | 37 | it('should fail', function (done) { 38 | var test = new Runnable('synchronous', function () { 39 | throw new Error('You had one job') 40 | }) 41 | 42 | test.run(function (err) { 43 | assert(err instanceof Error) 44 | assert.equal(err.message, 'You had one job') 45 | 46 | return done() 47 | }) 48 | }) 49 | }) 50 | 51 | describe('promise', function () { 52 | it('should pass', function (done) { 53 | var test = new Runnable('promise', function () { 54 | return defer() 55 | }) 56 | 57 | test.run(done) 58 | }) 59 | 60 | it('should fail', function (done) { 61 | var test = new Runnable('promise', function () { 62 | return new Promise(function (resolve, reject) { 63 | return setTimeout(function () { 64 | return reject(new Error('You promised me')) 65 | }, 0) 66 | }) 67 | }) 68 | 69 | test.run(function (err) { 70 | assert(err instanceof Error) 71 | assert.equal(err.message, 'You promised me') 72 | 73 | return done() 74 | }) 75 | }) 76 | }) 77 | 78 | describe('callback', function () { 79 | it('should pass', function (done) { 80 | var test = new Runnable('callback', function (done) { 81 | return setTimeout(done, 0) 82 | }) 83 | 84 | test.run(done) 85 | }) 86 | 87 | it('should fail', function (done) { 88 | var test = new Runnable('callback', function (done) { 89 | return setTimeout(function () { 90 | return done(new Error('You never called me back')) 91 | }, 0) 92 | }) 93 | 94 | test.run(function (err) { 95 | assert(err instanceof Error) 96 | assert.equal(err.message, 'You never called me back') 97 | 98 | return done() 99 | }) 100 | }) 101 | }) 102 | 103 | describe('generators', function () { 104 | var TEST_SOURCE = [ 105 | '(function * () {', 106 | ' yield defer()', 107 | '})' 108 | ].join('\n') 109 | 110 | var TEST_ERROR_SOURCE = [ 111 | '(function * () {', 112 | ' yield defer()', 113 | ' throw new Error(\'This generation has failed\')', 114 | '})' 115 | ].join('\n') 116 | 117 | describe('es6', function () { 118 | try { 119 | eval('(function * () {})') 120 | } catch (e) { 121 | console.log('Generators are not supported natively, skipping...') 122 | 123 | return 124 | } 125 | 126 | it('visual debugging', function * () { 127 | yield Promise.resolve('This is purely for testing Mocha HTML output') 128 | }) 129 | 130 | it('should pass', function (done) { 131 | var test = new Runnable('es6', eval(TEST_SOURCE)) 132 | 133 | test.run(done) 134 | }) 135 | 136 | it('should fail', function (done) { 137 | var test = new Runnable('es6', eval(TEST_ERROR_SOURCE)) 138 | 139 | test.run(function (err) { 140 | assert(err instanceof Error) 141 | assert.equal(err.message, 'This generation has failed') 142 | 143 | return done() 144 | }) 145 | }) 146 | }) 147 | 148 | if (isNode) { 149 | var traceur = require('traceur') 150 | var regenerator = require('regenerator') 151 | 152 | describe('regenerator', function () { 153 | it('should pass', function (done) { 154 | var test = new Runnable('regenerator', eval(regenerator.compile(TEST_SOURCE, { 155 | includeRuntime: true 156 | }).code)) 157 | 158 | test.run(done) 159 | }) 160 | 161 | it('should fail', function (done) { 162 | var test = new Runnable('regenerator', eval( 163 | regenerator.compile(TEST_ERROR_SOURCE, { 164 | includeRuntime: true 165 | }).code 166 | )) 167 | 168 | test.run(function (err) { 169 | assert(err instanceof Error) 170 | assert.equal(err.message, 'This generation has failed') 171 | 172 | return done() 173 | }) 174 | }) 175 | }) 176 | 177 | describe('traceur', function () { 178 | it('should pass', function (done) { 179 | var test = new Runnable( 180 | 'regenerator', eval(traceur.compile(TEST_SOURCE)) 181 | ) 182 | 183 | test.run(done) 184 | }) 185 | 186 | it('should fail', function (done) { 187 | var test = new Runnable( 188 | 'regenerator', eval(traceur.compile(TEST_ERROR_SOURCE)) 189 | ) 190 | 191 | test.run(function (err) { 192 | assert(err instanceof Error) 193 | assert.equal(err.message, 'This generation has failed') 194 | 195 | return done() 196 | }) 197 | }) 198 | }) 199 | } 200 | }) 201 | }) 202 | -------------------------------------------------------------------------------- /testem.json: -------------------------------------------------------------------------------- 1 | { 2 | "framework": "mocha", 3 | "src_files": [ 4 | "node_modules/chai/chai.js", 5 | "node_modules/es6-promise/dist/es6-promise.js", 6 | "co-mocha.js", 7 | "test.js" 8 | ], 9 | "launchers": { 10 | "Node": { 11 | "command": "node --harmony node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- -R tap --require lib/co-mocha.js --bail", 12 | "protocol": "tap" 13 | } 14 | }, 15 | "launch_in_dev": [ 16 | "Node" 17 | ] 18 | } 19 | --------------------------------------------------------------------------------