Skip to content

Commit f932622

Browse files
committed
QUnitReporter: update QUnit reporter based on the js-reporter adapter.
1 parent 01fe427 commit f932622

File tree

2 files changed

+54
-43
lines changed

2 files changed

+54
-43
lines changed

lib/_patch/my-mocha.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(function() {
2+
var runner = new JsReporters.MochaAdapter(mocha);
3+
var errors = []
4+
var passed = 0, failed = 0, total = 0;
5+
var startTime;
6+
7+
runner.on('runStart', function() {
8+
startTime = new Date()
9+
});
10+
11+
runner.on('testEnd', function(test) {
12+
total = total + 1;
13+
14+
passed = passed + (test.status === 'passed' ? 1 : 0);
15+
failed = failed + (test.status === 'failed' ? 1 : 0);
16+
17+
test.errors.forEach(function(error) {
18+
errors.push(error)
19+
});
20+
});
21+
22+
runner.on('runEnd', function() {
23+
var results = {}
24+
25+
results.runtime = new Date() - startTime;
26+
results.total = total;
27+
results.passed = passed;
28+
results.failed = failed;
29+
results.tracebacks = errors;
30+
results.url = window.location.pathname;
31+
32+
BrowserStack.post("/_report", results, function() {});
33+
});
34+
})();

lib/_patch/qunit-plugin.js

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,33 @@
77
factory(QUnit);
88
}
99
}(function(QUnit) {
10-
var failedAssertions = [];
11-
var options,
12-
currentModule,
13-
currentTest,
14-
setTimeoutVariable;
15-
var pendingTest = {};
10+
var runner = new JsReporters.QUnitAdapter(QUnit);
11+
var tracebacks = [];
12+
var total = 0,
13+
passed = 0,
14+
failed = 0;
1615

17-
var testTimeout = function() {
18-
var error = {
19-
testName: currentTest,
20-
message: "Stuck on this test for 60 sec."
21-
};
16+
runner.on('testEnd', function(test) {
17+
total = total + 1
2218

23-
BrowserStack.post('/_progress', {
24-
tracebacks: [error]
25-
}, function(){});
26-
};
19+
passed = passed + (test.status === 'passed' ? 1 : 0);
20+
failed = failed + (test.status === 'failed' ? 1 : 0);
2721

28-
QUnit.testDone(function(details) {
29-
var ct = details.module + " - " + details.name;
30-
clearTimeout(pendingTest[ct]);
22+
test.errors.forEach(function(error) {
23+
tracebacks.push(error)
24+
});
3125
});
3226

33-
QUnit.testStart(function(details) {
34-
currentTest = details.module + " - " + details.name;
35-
pendingTest[currentTest] = setTimeout(function() {
36-
testTimeout(currentTest);
37-
}, 60000);
38-
});
39-
40-
QUnit.log(function(details) {
41-
if (details.result) {
42-
return;
43-
}
44-
45-
var error = {
46-
actual: details.actual,
47-
expected: details.expected,
48-
message: details.message,
49-
source: details.source,
50-
testName:( details.module + ": " + details.name)
51-
};
27+
runner.on('runEnd', function(globalSuite) {
28+
var results = {};
5229

53-
BrowserStack.post('/_progress', {
54-
tracebacks: [error]
55-
}, function(){});
56-
});
57-
58-
QUnit.done(function(results) {
30+
results.runtime = globalSuite.runtime;
31+
results.total = total;
32+
results.passed = passed;
33+
results.failed = failed;
34+
results.tracebacks = tracebacks;
5935
results.url = window.location.pathname;
36+
6037
BrowserStack.post("/_report", results, function(){});
6138
});
6239
}));

0 commit comments

Comments
 (0)