0

whats up?

I have this struct in my project: https://i.stack.imgur.com/kKmkw.jpg

I have the file database.js which is some connection methods. (https://github.com/viniciusmurad/genericProject-node/blob/master/config/database.js)

In my server.js file I have a request from the database.

require('./config/database')('localhost/generic');

My question:

I'm wanting to create an auxiliary database for testing. I'm using gulp task to start mocha

gulp.task('test', function() {
    env({vars: {ENV:'Test'}});
    gulp.src('test/*.js', {read: false})
        .pipe(gulpMocha({reporter: 'nyan' }))
})

I thought of something:

var db;
if(process.env.ENV == 'Test') {
    db = mongoose.connect('localhost/generic_test');
}
else {
    db = mongoose.connect('localhost/generic');
} 

But where should I put the above function in accordance with the structure of my project?

Thankss

Gansonic
  • 347
  • 4
  • 15
  • 1
    You would have to add it to your test files. Might be a better solution to mock (sinon for instance) the database interface so you do not need the actual database and data, and simply test your code works based on hard returned results from the database mock. – Steven Scott Aug 16 '16 at 18:40
  • Thanks, I'll try it – Gansonic Aug 16 '16 at 23:37

0 Answers0