-
Notifications
You must be signed in to change notification settings - Fork 22
/
wallaby.js
84 lines (70 loc) · 2.07 KB
/
wallaby.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
module.exports = function () {
return {
files: [
'api/**/*.js',
'config/**/*.*',
'test/fixtures/**/*.*'
],
tests: ['test/unit/**/*.test.js'],
bootstrap: function (wallaby) {
if (global.sails) return;
var freeport = require('freeport');
var path = require('path');
var cp = require('child_process');
var fs = require('fs');
var fork = cp.fork;
var existsSync = fs.existsSync;
// Replacing fork to make sails start grunt in local project folder
cp.fork = function (file, args, opts) {
if (file.indexOf('grunt-cli')) {
opts.cwd = wallaby.localProjectDir;
}
return fork.apply(this, arguments);
};
// Replacing existsSync to make sails not throw error when it doesn't find node module in wallaby cache.
// Wallaby will use local node module anyway.
fs.existsSync = function (filePath) {
if (filePath && filePath.indexOf(path.join('instrumented', 'node_modules'))) {
return true;
}
return existsSync.apply(this, arguments);
};
wallaby.delayStart();
wallaby.testFramework.ui('bdd');
var Sails = require('sails');
var should = require('should');
var Barrels = require('barrels');
freeport(function (err, port) {
if (err) throw err;
// Lift Sails with test database
global.sails = Sails.lift({
log: {
level: 'info'
},
models: {
connection: 'test',
migrate: 'drop'
},
port: port
}, function (err) {
if (err) {
if (err) throw err;
wallaby.start();
}
// Load fixtures
var barrels = new Barrels();
// Save original objects in `fixtures` variable
fixtures = barrels.data;
// Populate the DB
barrels.populate(function (err) {
if (err) throw err;
wallaby.start();
});
});
});
},
env: {
type: 'node'
}
};
};