Tests Pass Locally, But Travis CI Builds Fails

I recently built some tests, to test my mongoDB to make sure it was operating properly. I ran my tests locally and they all passed. However, when I tried to push my changes to github, Travis would fail my test. This was the error:

User Controller
1) “before all” hook
2) “before each” hook
0 passing (21ms)
2 failing
1) User Controller “before all” hook:
Uncaught Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1012:19)
2) User Controller “before each” hook:
TypeError: Cannot read property ‘call’ of undefined

The issue turned out to be that Travis was trying to connect to my mongoDB and could not establish a connection. The test I wrote, that connected to mongoDB is below.

var chai = require(‘chai’)
var expect = chai.expect;
var mongoose = require(‘mongoose’);
var helpers = require(‘./../server/helpers.js’);
var db = require(‘./../db/db’);
var dbURI = ‘mongodb://localhost/SomeRandomDataBase’;
var clearDB = function (done) {
describe(‘User Controller’, function () {
// Connect to database before any tests
before(function (done) {
if (mongoose.connection.db) {
return done();
mongoose.connect(dbURI, done);

The key to fixing this was to update my .travis.yml file.

– npm update -g npm
sudo: required
language: node_js
– ‘0.12’
services: < — — — — — -This was the soultion
– mongodb
provider: heroku
secure: SomeRandomEncryptedKey

After updating my .travis.yml file, I successfully managed to push my changes to github and to get my tests to pass Travis.

Like what you read? Give Brandon Stookey a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.