forked from rosshinkley/mongoose-multitenant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
95 lines (87 loc) · 1.9 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var f, semver, async, _;
var fs = require('fs');
semver = require('semver');
async = require('async');
_ = require('underscore');
f = require('util').format;
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-sed');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.initConfig({
version: grunt.file.readJSON('package.json').version,
watch: {
coffee:{
files:['coffee/**/*.coffee', 'coffee/*.coffee'],
tasks:['coffee']
}
},
exec:{
test: {
cmd:function(ex) {
return f('NODE_ENV=test mocha %s', ex)
}
}
},
coffee: {
source:{
options:{
preserve_dirs:true,
bare:true
},
files:[
{
expand:true,
flatten:false,
cwd:'coffee',
src:['*.coffee','**/*.coffee'],
dest:'',
ext:'.js'
}
]
}
}
});
grunt.registerTask('dropTestDb', function() {
var mongoose = require('mongoose');
var done = this.async();
async.series(_.map([
'mongodb://localhost/multitenant_test_one',
'mongodb://localhost/multitenant_test_two',
'mongodb://localhost/multitenant_test'
], function(db){
return function(cb){
mongoose.connect(db, function(){
mongoose.connection.db.dropDatabase(function(err){
if(err){
console.log(err);
}else{
console.log('Successfully dropped %s', db);
}
mongoose.connection.close(cb);
});
});
};
}), function(err){
done();
});
});
grunt.registerTask('test', 'Run tests', function(test) {
var tasks = []
var files = fs.readdirSync('test');
var file;
if(test) {
tasks.push('exec:test:"test/' + test + '.js' + '"')
tasks.push('dropTestDb')
}
else {
for(var i=0;i<files.length;i++) {
file = files[i];
tasks.push('exec:test:"test/' + file + '"')
tasks.push('dropTestDb')
}
}
grunt.task.run(tasks);
});
};