-
Notifications
You must be signed in to change notification settings - Fork 46
/
reporter.js
89 lines (79 loc) · 2.17 KB
/
reporter.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
MochaWeb = this.MochaWeb = {};
if (Meteor.isServer)
var Base = Npm.require("mocha/lib/reporters").Base;
else
Base = Mocha.reporters.Base
function getAncestors(testObject, ancestors){
if (!ancestors)
ancestors = []
if (testObject.parent && testObject.parent.title !== ""){
ancestors.push(testObject.parent.title)
return getAncestors(testObject.parent, ancestors);
}
else{
return ancestors;
}
};
MochaWeb.MeteorCollectionTestReporter = function(runner){
Base.call(this, runner);
var self = this;
function saveTestResult(test){
if (test.state === "failed"){
console.log(test.err.message);
console.log(test.err.stack);
}
// console.log("SAVE TEST RESULT", test);
var ancestors = getAncestors(test);
var result = {
id: "mocha:" + ancestors.join(":") + ":" + test.title,
async: !!test.async,
framework: "mocha",
name: test.title,
pending: test.pending,
result: test.state,
duration: test.duration,
timeOut: test._timeout,
timedOut: test.timedOut,
ancestors: ancestors,
isClient: Meteor.isClient,
isServer: Meteor.isServer,
timestamp: new Date()
};
if (typeof test.state === "undefined" && test.pending === true) {
result.result = "pending";
}
if (test.err){
result.failureMessage = test.err.message;
result.failureStackTrace = test.err.stack;
}
// console.log("POSTING RESULT", result);
ddpParentConnection.call("velocity/reports/submit", result, function(error, result){
if (error){
console.error("ERROR WRITING TEST", error);
}
});
}
runner.on("start", Meteor.bindEnvironment(
function(){
//TODO tell testRunner that mocha tests have started
},
function(err){
throw err;
}
));
["pass", "fail", "pending"].forEach(function(testEvent){
runner.on(testEvent, Meteor.bindEnvironment(
function(test){
saveTestResult(test);
},
function(err){
throw err;
}
));
});
runner.on('end', Meteor.bindEnvironment(function(){
//TODO tell testRunner all mocha web tests have finished
}, function(err){
throw err;
}));
};