Skip to content

Commit 56dc01a

Browse files
committed
Fix for Issue #177
The code that works with Jasmine is completely different from the one working with Mocha and QUnit. The results sent to '_report' API in case of Jasmine has very limited information resulting in the case as described in this issue. It was found that the Jasmine reports are actually as good as Mocha and it's our code that does not let it pass through in its entirety causing the limited information. - jasmine-jsreporter.js: it has the code that prepares per test suite report, and cuts out detailed information. It was modified to retain detailed information. Also some 'summarization' attributes are just duplicate state, and hence they were removed - jasmine-plugin.js: it has code that further summarizes the reports created per suite in jasmine-jsreporter.js before making a call to the '_report' API. It was modified to retain detailed information. - server.js: for Jasmine case, a 'reformatting' adapter function is added. With the changes done in above files, detailed information as good as Mocha is available; however, the structure is different. This function adapts the structure such that the final reports are in the format desired. This function is called in the handler for '_report' API. Limitations/Differences - There is no equivalent of '_progress' API here. The 'tests' attribute at the topmost level is built in the '_progress' API in case of Mocha. This API gets called as each test completes with Mocha. In Jasmine case, we build the 'tests' attribute in the handler for '_report' call itself. - In case of Mocha, whether it's an assertion failure or an uncaught exception, stack trace is available for both cases. In Jasmine case, stack trace is available only in case of uncaught exceptions. In case of assertion failures, Jasmine provides only a message, not a trace.
1 parent 8afbecb commit 56dc01a

File tree

3 files changed

+103
-7
lines changed

3 files changed

+103
-7
lines changed

lib/_patch/jasmine-jsreporter.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@
7575
description : specs[i].description,
7676
durationSec : specs[i].durationSec,
7777
passed : specs[i].results().passedCount === specs[i].results().totalCount,
78-
skipped : specs[i].results().skipped,
79-
passedCount : specs[i].results().passedCount,
80-
failedCount : specs[i].results().failedCount,
81-
totalCount : specs[i].results().totalCount
78+
results : specs[i].results()
8279
};
8380
suiteData.passed = !suiteData.specs[i].passed ? false : suiteData.passed;
8481
suiteData.durationSec += suiteData.specs[i].durationSec;

lib/_patch/jasmine-plugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
for (var i = 0; i < suite.specs.length; ++i) {
44
if (suite.specs[i].passed){
55
results.passed++;
6+
}
7+
else if(suite.specs[i].results.skipped) {
8+
results.skipped++;
69
} else {
7-
results.tracebacks.push(suite.specs[i].description);
810
results.failed++;
911
}
1012
}
@@ -26,17 +28,18 @@
2628
results.total = 0;
2729
results.passed = 0;
2830
results.failed = 0;
29-
results.tracebacks = [];
31+
results.skipped = 0;
3032

3133
for (var i = 0; i < report.suites.length; ++i) {
3234
if (report.suites[i]) {
3335
results = countSpecs(report.suites[i], results);
3436
}
3537
}
3638

37-
results.total = results.passed + results.failed;
39+
results.total = results.passed + results.failed + results.skipped;
3840

3941
results.url = window.location.pathname;
42+
results.report = report
4043
BrowserStack.post("/_report", results, function(){});
4144
clearInterval(checker);
4245
}

lib/server.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,101 @@ exports.Server = function Server(bsClient, workers, config, callback) {
3939
return browserReport;
4040
}
4141

42+
function reformatJasmineReport(browserReport) {
43+
var results = browserReport.suites;
44+
browserReport.tests = browserReport.tests || [ ];
45+
browserReport.suites = {
46+
fullName : [ ],
47+
childSuites : [ ],
48+
tests : [ ],
49+
status : !results.failed ? 'passed' : 'failed',
50+
testCounts : {
51+
passed : results.passed,
52+
failed : results.failed,
53+
skipped : results.skipped,
54+
total : results.total,
55+
},
56+
runtime : results.runtime
57+
};
58+
function recurseThroughSuites(jasmineSuite, par) {
59+
var suite = {
60+
name : jasmineSuite.description,
61+
fullName: [ ],
62+
childSuites : [ ],
63+
tests: [ ],
64+
status : jasmineSuite.passed ? 'passed' : 'failed',
65+
testCounts : {
66+
passed : 0,
67+
failed : 0,
68+
skipped: 0,
69+
total: 0
70+
},
71+
runtime: 0
72+
};
73+
if(par.name) {
74+
suite.fullName.push(par.name);
75+
}
76+
suite.fullName.push(jasmineSuite.description);
77+
jasmineSuite.specs.forEach(function(spec) {
78+
var test = {
79+
name : spec.description,
80+
suiteName : suite.decription,
81+
fullName : [
82+
],
83+
status : spec.passed ? 'passed' : (spec.results.skipped ? 'skipped' : 'failed'),
84+
runtime : spec.durationSec,
85+
errors : [ ],
86+
assertions : [ ]
87+
};
88+
Array.prototype.push.apply(test.fullName, suite.fullName);
89+
test.fullName.push(spec.description);
90+
if(!spec.passed) {
91+
spec.results.items_.forEach(function(jasmineItem) {
92+
if(!jasmineItem.passed_) {
93+
var detail = {
94+
passed : false
95+
};
96+
if('message' in jasmineItem) {
97+
detail.message = jasmineItem.message;
98+
}
99+
if('actual' in jasmineItem) {
100+
detail.actual = jasmineItem.actual;
101+
}
102+
if('expected' in jasmineItem) {
103+
detail.expected = jasmineItem.expected;
104+
}
105+
if('trace' in jasmineItem) {
106+
detail.stack = jasmineItem.trace.message || jasmineItem.trace.stack;
107+
}
108+
test.errors.push(detail);
109+
test.assertions.push(detail);
110+
}
111+
});
112+
}
113+
suite.tests.push(test);
114+
browserReport.tests.push(test);
115+
if(spec.passed) {
116+
++suite.testCounts.passed;
117+
}
118+
else if(spec.skipped) {
119+
++suite.testCounts.skipped;
120+
}
121+
else {
122+
++suite.testCounts.failed;
123+
}
124+
++suite.testCounts.total;
125+
suite.runtime += spec.durationSec;
126+
});
127+
jasmineSuite.suites.forEach(function(childSuite) {
128+
recurseThroughSuites(childSuite, suite);
129+
});
130+
par.childSuites.push(suite);
131+
}
132+
results.report.suites.forEach(function(jasmineSuite) {
133+
recurseThroughSuites(jasmineSuite, browserReport.suites);
134+
});
135+
}
136+
42137
function handleFile(filename, request, response, doNotUseProxy) {
43138
var url_parts = url.parse(request.url, true);
44139
var query = url_parts.query;
@@ -293,6 +388,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
293388
color = ( query.total !== query.passed ) ? 'red' : 'green';
294389
logger.info('[%s] ' + chalk[color](( query.total !== query.passed ) ? 'Failed:' : 'Passed:') + ' %d tests, %d passed, %d failed; ran for %dms', browserInfo, query.total, query.passed, query.failed, query.runtime);
295390
config.status += query.failed;
391+
reformatJasmineReport(browserReport);
296392
} else if(query.testCounts) {
297393
color = query.status === 'failed' ? 'red' : 'green';
298394
logger.info('[%s] ' + chalk[color](query.status === 'failed' ? 'Failed:' : 'Passed:') + ' %d tests, %d passed, %d failed, %d skipped; ran for %dms', browserInfo, query.testCounts.total, query.testCounts.passed, query.testCounts.failed, query.testCounts.skipped, query.runtime);

0 commit comments

Comments
 (0)