I'm using supertest to unit test my server configurations and route handlers. The server configurations tests are in test.server.js
and the route handling tests are in test.routes.handlers.js
.
When I run all the test files using mocha .
, I get EADDRINUSE
. When I run each file individually, everything works as expected.
Both files define and require supertest, request = require('supertest')
, and the express server file, app = require('../server.js')
. In server.js
, the server is started like so:
http.createServer(app).listen(app.get('port'), config.hostName, function () {
console.log('Express server listening on port ' + app.get('port'));
});
Is there something wrong in my implementation? How can I avoid EADDRINUSE
error when running my tests?