Created
October 19, 2017 21:11
-
-
Save yattias/62ec1cd0233617901824aa14649037bf to your computer and use it in GitHub Desktop.
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
// Drops all mongo collections associated with a test Database before running any tests. | |
process.env.NODE_ENV = 'test'; | |
import mongoose from 'mongoose'; | |
import settings from '../../src/config/settings'; | |
before(async function(){ | |
const dropCollection = (name) => { | |
return new Promise(function(resolve, reject){ | |
mongoose.connection.collections[name].drop(function(err){ | |
resolve(); | |
}); | |
}); | |
} | |
const collectionNames = Object.keys(mongoose.connection.collections); | |
let currentCollection; | |
for (let i = 0; i < collectionNames.length; i++) { | |
currentCollection = collectionNames[i]; | |
await dropCollection(currentCollection); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment