From de129c289dc17d3039c2655c050716b0eff9b0f5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 1 Oct 2017 00:48:29 -0400 Subject: [PATCH] tests: run mocha with --no-exit to detect hangs closes #3439 --- package.json | 8 ++++---- test/middleware.basic.js | 2 +- test/res.format.js | 11 +++++++---- test/res.sendFile.js | 30 ++++++++++++++++++------------ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 3b03f12d92..6bfc610ccf 100644 --- a/package.json +++ b/package.json @@ -90,9 +90,9 @@ ], "scripts": { "lint": "eslint .", - "test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/", - "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/", - "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/", - "test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/" + "test": "mocha --require test/support/env --reporter spec --bail --check-leaks --no-exit test/ test/acceptance/", + "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks --no-exit test/ test/acceptance/", + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks --no-exit test/ test/acceptance/", + "test-tap": "mocha --require test/support/env --reporter tap --check-leaks --no-exit test/ test/acceptance/" } } diff --git a/test/middleware.basic.js b/test/middleware.basic.js index 28a4dd18f2..ce59589230 100644 --- a/test/middleware.basic.js +++ b/test/middleware.basic.js @@ -28,7 +28,7 @@ describe('middleware', function(){ }); }); - request(app.listen()) + request(app) .get('/') .set('Content-Type', 'application/json') .send('{"foo":"bar"}') diff --git a/test/res.format.js b/test/res.format.js index 3c1d095b42..1c1d077e58 100644 --- a/test/res.format.js +++ b/test/res.format.js @@ -1,4 +1,5 @@ +var after = require('after') var express = require('../') , request = require('supertest') , assert = require('assert'); @@ -168,21 +169,23 @@ function test(app) { .expect('hey', done); }) - it('should set the correct charset for the Content-Type', function() { + it('should set the correct charset for the Content-Type', function (done) { + var cb = after(3, done) + request(app) .get('/') .set('Accept', 'text/html') - .expect('Content-Type', 'text/html; charset=utf-8'); + .expect('Content-Type', 'text/html; charset=utf-8', cb) request(app) .get('/') .set('Accept', 'text/plain') - .expect('Content-Type', 'text/plain; charset=utf-8'); + .expect('Content-Type', 'text/plain; charset=utf-8', cb) request(app) .get('/') .set('Accept', 'application/json') - .expect('Content-Type', 'application/json'); + .expect('Content-Type', 'application/json; charset=utf-8', cb) }) it('should Vary: Accept', function(done){ diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 4b1f3852f3..ccec3f40cf 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -102,7 +102,7 @@ describe('res', function(){ app.use(function (req, res) { setImmediate(function () { res.sendFile(path.resolve(fixtures, 'name.txt')); - cb(); + server.close(cb) }); test.abort(); }); @@ -112,7 +112,8 @@ describe('res', function(){ cb(); }); - var test = request(app).get('/'); + var server = app.listen() + var test = request(server).get('/') test.expect(200, cb); }) @@ -264,13 +265,14 @@ describe('res', function(){ res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) { should(err).be.ok() err.code.should.equal('ECONNABORTED'); - cb(); + server.close(cb) }); }); test.abort(); }); - var test = request(app).get('/'); + var server = app.listen() + var test = request(server).get('/') test.expect(200, cb); }) @@ -283,13 +285,14 @@ describe('res', function(){ res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) { should(err).be.ok() err.code.should.equal('ECONNABORTED'); - cb(); + server.close(cb) }); }); test.abort(); }); - var test = request(app).get('/'); + var server = app.listen() + var test = request(server).get('/') test.expect(200, cb); }) @@ -388,13 +391,14 @@ describe('res', function(){ res.sendfile('test/fixtures/name.txt', function (err) { should(err).be.ok() err.code.should.equal('ECONNABORTED'); - cb(); + server.close(cb) }); }); test.abort(); }); - var test = request(app).get('/'); + var server = app.listen() + var test = request(server).get('/') test.expect(200, cb); }) @@ -407,13 +411,14 @@ describe('res', function(){ res.sendfile('test/fixtures/name.txt', function (err) { should(err).be.ok() err.code.should.equal('ECONNABORTED'); - cb(); + server.close(cb) }); }); test.abort(); }); - var test = request(app).get('/'); + var server = app.listen() + var test = request(server).get('/') test.expect(200, cb); }) @@ -629,7 +634,7 @@ describe('res', function(){ app.use(function (req, res) { setImmediate(function () { res.sendfile(path.resolve(fixtures, 'name.txt')); - cb(); + server.close(cb) }); test.abort(); }); @@ -639,7 +644,8 @@ describe('res', function(){ cb(); }); - var test = request(app).get('/'); + var server = app.listen() + var test = request(server).get('/') test.expect(200, cb); })