spion/blue-tape

Provide support for generator functions

sladiri opened this issue · 1 comments

Hi, I am currently using blue-tape with babel-tape-runner and co.js to use generator functions. Is it possible to pass a generator function instead of a normal one returning a promise?
Here is my test:

test('generators work', t =>
    co(function* () {
        const fixture = setup();

        const response = yield supertest(fixture.server)
            .post('/')
            .end();

        t.equal(response.headers['content-type'], 'application/json; charset=utf-8',
            'type should be JSON and UTF-8');

        teardown(fixture);
    })
);

Here is what I would like to do:

test('generators work', function* (t) {
        const fixture = setup();

        const response = yield supertest(fixture.server)
            .post('/')
            .end();

        t.equal(response.headers['content-type'], 'application/json; charset=utf-8',
            'type should be JSON and UTF-8');

        teardown(fixture);
});

I read that blue-tape somehow supports generators, but I could not get this to work.

I realized that I could just wrap my function inside co() would be enough, so it is already supported well.

test('generators work', t => co(function* () {
        const fixture = setup();

        const response = yield supertest(fixture.server)
            .post('/')
            .end();

        t.equal(response.headers['content-type'], 'application/json; charset=utf-8',
            'type should be JSON and UTF-8');

        teardown(fixture);
}));