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

Mocha test using supertest doesn't exit when used with gulp-mocha #121

Closed
kanchamreddy opened this issue Mar 25, 2014 · 7 comments
Closed

Comments

@kanchamreddy
Copy link

If I run my tests which use supertest, the process doesn't seem to exit. Had to use Ctrl+C to kill the process.

Not sure if this is an issue with supertest or gulp-mocha.

The gulp npm test task also doesn't exit, unless explicitly exited with process.exit(-1)

gulpfile.js

'use strict';
var gulp = require('gulp');


var mocha = require('gulp-mocha');
var testScriptPaths = ['tests/**/*.js'];

function handleError(err) {
  console.log(err.toString());
  this.emit('end');
}

gulp.task('test', function() {
    gulp.src(testScriptPaths)
        .pipe(mocha({ reporter: 'spec' }))
        .on('error', handleError);
});

gulp.task('npm', ['test'], function(done) {
    require('child_process').spawn('npm', ['test'], { stdio: 'inherit' })
    .on('close', function(e) {
        console.log(e);
        process.exit(-1);
        done();
    });
});


gulp.task('default', ['test'], function() {});

Test file

var should = require('chai').should(),
    express = require('express'),
    request = require('supertest');

describe('request.agent(app)', function(){
  var app = express();

  app.use(express.cookieParser());

  app.get('/', function(req, res){
    res.cookie('cookie', 'hey');
    res.send();
  });

  app.get('/return', function(req, res){
    if (req.cookies.cookie) res.send(req.cookies.cookie);
    else res.send(':(')
  });

  var agent = request.agent(app);

  it('should save cookies', function(done){
    agent
    .get('/')
    .expect('set-cookie', 'cookie=hey; Path=/', done);
  })

  it('should send cookies', function(done){
    agent
    .get('/return')
    .expect('hey', done);
  })
})
@invernizzie
Copy link
Contributor

This is probably due to #100. A patch has been merged to master but wasn't included in a release yet. You could check by using this repo's master branch (or the specific commit that fixes this, here) as the target version in your project.json (instead of a semver like 0.10.0, the latest release).

@gjohnson
Copy link
Contributor

Try 0.11.0, it has fixed this problem. If you still see an issue, it's going to be a problem with the gulp task.

@niftylettuce
Copy link
Collaborator

@gjohnson can we get a full example put somewhere for how to use gulp with gulp-mocha? everyones' documentation is different and I'm constantly seeing bugs with streams and async stuff

@cellis
Copy link

cellis commented Nov 17, 2014

Yeah this still doesn't work for me with gulp-mocha. I'm just going to use https://github.com/dreame4/gulp-exit.

@juanpabloaj
Copy link

+1

@ShakedBuildup
Copy link

+1

@niftylettuce
Copy link
Collaborator

Instead of using supertest I'm now using https://github.com/niftylettuce/frisbee

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

7 participants