Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 4.0 and Mocha Generator Functions #1891

Closed
dschinkel opened this issue Sep 14, 2015 · 7 comments
Closed

Node 4.0 and Mocha Generator Functions #1891

dschinkel opened this issue Sep 14, 2015 · 7 comments

Comments

@dschinkel
Copy link

Just wondering if I need to try to use middleware such as gulp-mocha-co or mocha-generators since Node 4.0 includes support for generators via ES6.

So should we assume we should be able to now run tests like this with Node 4.0 which would use ES6 natively?

it('should return all countries when no id passed', function*(done){

    ..some code
    responseModel.countries.should.have.length(2);
    responseModel.countries[0].id.should.equal(55);
    responseModel.countries[1].id.should.equal(10);
    done();
});
@danielstjules
Copy link
Contributor

ES6 supports generators, but coroutines are a little different. While you might be able to use generator functions with specs, mocha doesn't do anything special for coroutine support (what allows you to yield promises) This was proposed in #1575 but closed.

In the meantime, it looks like https://github.com/blakeembrey/co-mocha is the recommended solution! :)

@dschinkel

This comment was marked as abuse.

@dschinkel

This comment was marked as abuse.

@danielstjules
Copy link
Contributor

co-mocha doesn't depend on the --harmony flag, it only depends on generators being enabled. With node 4, they're enabled by default. So if you were using --harmony-generators or --harmony with node 0.12 or iojs, you don't need those flags anymore :)

@dschinkel

This comment was marked as abuse.

@dschinkel

This comment was marked as abuse.

@danielstjules
Copy link
Contributor

Oh, gulp-mocha-co uses a fork of mocha (https://github.com/ilkkao/co-mocha) Didn't realize that.

Instead, I'd just use: https://github.com/sindresorhus/gulp-mocha with https://github.com/blakeembrey/co-mocha Then, your config could look something like:

var gulp = require('gulp');
var mocha = require('gulp-mocha');

gulp.task('default', function () {
    return gulp.src('test.js', {read: false})
        .pipe(mocha({require: 'co-mocha'}));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants