Created
September 30, 2015 17:36
-
-
Save alexandrusavin/318e0a7593c1a8cbe94f to your computer and use it in GitHub Desktop.
root mocha setup for mongodb int tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var mongoose = require('mongoose'); | |
var _ = require('lodash'); | |
var conn; | |
function clearDB() { | |
var cleaned = []; | |
_.each(conn.collections, (function (col) { | |
cleaned.push(col.remove()); | |
})); | |
return Promise.all(cleaned); | |
} | |
beforeEach(function () { | |
if (!conn) { | |
conn = mongoose.createConnection('mongodb://localhost:21017/f2test'); | |
} else if (conn.readyState === 0) { | |
conn.on('open', function (err) { | |
if (err) { | |
throw err; | |
} | |
return clearDB(); | |
}); | |
} else { | |
return clearDB(); | |
} | |
}); | |
afterEach(function (done) { | |
conn.close(); | |
return done(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment