Last active
January 20, 2019 17:18
-
-
Save stackdumper/b44f8214652e2e970c6311040e139b20 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import ava from 'ava' | |
import nanoid from 'nanoid' | |
import mongoose from 'mongoose' | |
/* | |
test wrapper for ava | |
creates new database and drops it afterwards | |
*/ | |
export const test = (message, cb) => | |
ava(message, async (t) => { | |
const db = await mongoose.createConnection(`mongodb://localhost/test-${nanoid(5)}`) | |
try { | |
await cb(t, { db }) | |
} catch (error) { | |
throw error | |
} finally { | |
await db.connection.dropDatabase() | |
await db.connection.close() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment