UNPKG

1.29 kBJavaScriptView Raw
1if (typeof window !== 'undefined') {
2 window.completedTests = 0;
3 window.sawFail = false;
4 window.onload = function () {
5 window.testsPassed = null;
6 var handleResults = function (runner) {
7 var failedTests = [];
8 if (runner.stats.end) {
9 window.testsPassed = runner.stats.failures === 0;
10 }
11 runner.on('pass', function () {
12 window.completedTests += 1;
13 });
14 runner.on('fail', function (test, err) {
15 window.sawFail = true;
16 var flattenTitles = function (testToFlatten) {
17 var titles = [];
18 var currentTest = testToFlatten;
19 while (currentTest.parent.title) {
20 titles.push(currentTest.parent.title);
21 currentTest = currentTest.parent;
22 }
23 return titles.reverse();
24 };
25 failedTests.push({
26 name: test.title,
27 result: false,
28 message: err.message,
29 stack: err.stack,
30 titles: flattenTitles(test)
31 });
32 });
33 runner.on('end', function () {
34 window.testsPassed = !window.sawFail;
35 // for sauce
36 window.mochaResults = runner.stats;
37 window.mochaResults.reports = failedTests;
38 });
39 return runner;
40 };
41 handleResults(mocha.run());
42 };
43}