Supertest不返回结果,节点实例不退出

我只是在学习testing,我已经在这里几个小时没有成功。 每次我运行Mocha ,我的testing显示在terminal,并没有返回结果,如下所示:

 Express test app started on port: 3001 addition 

之后它保持空白。 而且,节点进程在testing之后不会closures,当它们堆积起来时,会使我的计算机崩溃。

这是我的样本testing:

 var supertest = require('supertest'); var should = require('should'); process.env.NODE_ENV = 'test'; var app = require('../server'); describe('addition', function() { //... previous test it('should return 2 given the url /add/1/1', function(done) { request(app) .get('/add/1/1') .expect(200) .end(function(err, res) { should.not.exist(err); parseFloat(res.text).should.equal(2); done(); }); }); }); 

这是我的server.js

 // Module Depndencies var express = require('express'), fs = require('fs'), mongoose = require('mongoose'), passport = require('passport'), MongoStore = require('connect-mongo')(express), flash = require('connect-flash'), env = process.env.NODE_ENV = process.env.NODE_ENV || 'development', ErrorHandler = require('./app/controllers/api/v1/error_handler_v1'), config = require('./config/config'), auth = require('./config/middlewares/authorization'); // Connect The Database mongoose.connect(config.db); // Catch Database Connection Error mongoose.connection.on("error", function(err) { return console.log("****** Could not connect to mongo server!"); }); // Express Settings app = express(); app.set('showStackError', true); //Should be placed before express.static app.use(express.compress({ filter: function(req, res) { return (/json|text|javascript|css/).test(res.getHeader('Content-Type')); }, level: 9 })); //Setting the fav icon and static folder - tejkh app.use(express.favicon()); app.use(express.static(config.root + '/public')); //Don't use logger for test env if (process.env.NODE_ENV !== 'test') app.use(express.logger('dev')); //Set views path, template engine and default layout app.set('views', config.root + '/app/views'); app.set('view engine', 'jade'); // Enable jsonp app.enable('jsonp callback'); //Bootstrap models var models_path = __dirname + '/app/models'; var walk = function(path) { fs.readdirSync(path).forEach(function(file) { var newPath = path + '/' + file; var stat = fs.statSync(newPath); if (stat.isFile()) { if (/(.*)\.(js|coffee)/.test(file)) { require(newPath); } } else if (stat.isDirectory()) { walk(newPath); } }); }; walk(models_path); // Bootstrap Passport require('./config/passport')(passport); // App.configure app.configure(function() { // CookieParser should be above session app.use(express.cookieParser()); // BodyParser should be above methodOverride app.use(express.bodyParser()); app.use(express.methodOverride()); // Express/mongo session storage app.use(express.session({ secret: 'secret', cookie: { maxAge: 864000000 // 10 Days in miliseconds }, store: new MongoStore({ url: config.db, auto_reconnect: true }) })); // Connect flash for flash messages app.use(flash()); // Use Passport app.use(passport.initialize()); app.use(passport.session()); // Route app.use(app.router); // Error Handler app.use(function(err, req, res, next) { if (err.uri) delete err.uri; if (err.status) { return res.status(err.status).jsonp(err); } else { res.status(500).jsonp({ name: 'InternalError', message: 'Sorry, something went wrong on our end. We have been notified.', code: 'server_error', status: 500 }); } }); }); // app.configure //Bootstrap routes require('./config/routes')(app, passport, auth); // Start App app.listen(config.port); console.log('Express ' + env + ' app started on port: ' + config.port); // Expose app exports = module.exports = app; 

       

网上收集的解决方案 "Supertest不返回结果,节点实例不退出"