-
Notifications
You must be signed in to change notification settings - Fork 46
/
server.js
executable file
·104 lines (91 loc) · 2.61 KB
/
server.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
96
97
98
99
100
101
102
103
104
// Do not run tests if Velocity is not enabled
if (process.env.VELOCITY === "0") {
return;
}
//register the testing framework if this is the main app (not a mirror)
if (!process.env.IS_MIRROR){
Velocity.registerTestingFramework("mocha", {
regex: '^tests/mocha/.*$',
sampleTestGenerator: function(){
return [
{ path: "mocha/client/sampleClientTest.js",
contents: Assets.getText("sample-tests/client.js")
},
{ path: "mocha/server/sampleServerTest.js",
contents: Assets.getText("sample-tests/server.js")}
];
}
});
}
var clientTestsComplete = false;
var serverTestsComplete = false;
var Mocha = Npm.require("mocha");
var childProcess = Npm.require('child_process');
var path = Npm.require('path');
var mkdirp = Npm.require("mkdirp");
ddpParentConnection = null;
var parentUrl = null;
Meteor.startup(function(){
if (process.env.IS_MIRROR) {
console.log("MOCHA MIRROR LISTENING AT", process.env.ROOT_URL);
parentUrl = process.env.PARENT_URL;
ddpParentConnection = DDP.connect(parentUrl);
runServerTests = Meteor.bindEnvironment(function() {
console.log("Running mocha server tests");
mocha.run(Meteor.bindEnvironment(function(err){
if (err){
console.log("Error running server tests", err);
}
markTestsComplete();
}));
});
} else {
mirrorPort = process.env.MOCHA_MIRROR_PORT;
opt = {
framework: 'mocha',
testsPath: "mocha",
rootUrlPath: '?mocha=true',
}
if(mirrorPort) {
opt['port'] = parseInt(mirrorPort);
}
Meteor.call("velocity/mirrors/request", opt, function(err, msg){
if (err){
console.log("error requesting mirror", err);
}
});
}
});
var markTestsComplete = function(){
ddpParentConnection.call("velocity/reports/completed", {framework: "mocha"}, function(err){
if (err){
console.error("error calling testsComplete function", err);
}
});
};
Meteor.methods({
"mirrorInfo": function(){
return {
isMirror: process.env.IS_MIRROR,
parentUrl: process.env.PARENT_URL
};
},
"clientTestsComplete": function(){
runServerTests();
}
});
//if not a mirror don't do anything
MochaWeb.testOnly = function(callback){
// console.log("NO OP", mirror.isMirror);
};
function setupMocha(){
if (! process.env.IS_MIRROR)
return;
MochaWeb.testOnly = function(callback){
callback();
}
global.chai = Package['practicalmeteor:chai'].chai;
global.mocha = new Mocha({ui: "bdd", reporter: MochaWeb.MeteorCollectionTestReporter});
Package['mike:mocha-core'].setupGlobals(mocha);
}
setupMocha();