Skip to content

Commit f729107

Browse files
Add support for Saucelabs. Add a method of logging for when console.log isn’t available.
1 parent e3c2031 commit f729107

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

test.new/static/js/test_helpers.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,24 @@
2020
}
2121
}
2222

23+
function info_IE6() {
24+
var log = $('log');
25+
log.show();
26+
var results = [];
27+
for (var i = 0, len = arguments.length; i < len; i++) {
28+
results.push(arguments[i].toString());
29+
}
30+
var html = results.join(' ');
31+
var p = new Element('p', { 'class': 'log-item' });
32+
p.update(html);
33+
34+
log.insert(p);
35+
// Force the log to scroll to the bottom whenever new stuff happens.
36+
log.scrollTop = log.offsetHeight;
37+
}
38+
2339
if (!CONSOLE_LOG_SUPPORTED) {
24-
info = Prototype.emptyFunction;
40+
info = info_IE6;
2541
} else {
2642
try {
2743
console.log.apply(console, [""]);
@@ -246,7 +262,7 @@
246262
// Calling `remove` on this node has been known to crash the tests in
247263
// IE6-7.
248264
if (this.currentFixtures) {
249-
$('current_fixtures').update();
265+
document.getElementById('current_fixtures').innerHTML = '';
250266
}
251267

252268
if (this.fixtures[suite]) {
@@ -259,6 +275,35 @@
259275
if (CONSOLE_GROUP_SUPPORTED) {
260276
console.groupEnd();
261277
}
278+
},
279+
280+
configureRunner: function (runner) {
281+
var failedTests = [];
282+
runner.on('end', function(){
283+
window.mochaResults = runner.stats;
284+
window.mochaResults.reports = failedTests;
285+
});
286+
287+
runner.on('fail', logFailure);
288+
289+
function logFailure (test, err) {
290+
function flattenTitles (test) {
291+
var titles = [];
292+
while (test.parent.title) {
293+
titles.push(test.parent.title);
294+
test = test.parent;
295+
}
296+
return titles.reverse();
297+
}
298+
299+
failedTests.push({
300+
name: test.title,
301+
result: false,
302+
message: err.message,
303+
stack: err.stack,
304+
titles: flattenTitles(test)
305+
});
306+
}
262307
}
263308
};
264309

test.new/views/layout.erb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
#mocha li.test {
4040
clear: both;
4141
}
42+
43+
#log {
44+
width: 350px;
45+
position: absolute;
46+
top: 10px;
47+
left: 10px;
48+
height: 500px;
49+
overflow-y: auto;
50+
background: #fff;
51+
border: 2px solid #eee;
52+
}
4253
</style>
4354

4455
<!--[if lt IE 8]>
@@ -77,6 +88,9 @@
7788
</head>
7889

7990
<body data-suites="<%= suites.join(',') %>">
91+
92+
<!-- A DIV that we log into whenever console.log isn't available. -->
93+
<div id="log" style="display: none"></div>
8094
<div id="mocha"></div>
8195

8296
<div id="current_fixtures"></div>
@@ -90,9 +104,11 @@
90104
if (window.mochaPhantomJS) {
91105
mochaPhantomJS.run();
92106
} else {
93-
mocha.run();
107+
var runner = mocha.run();
94108
}
95109

110+
Test.configureRunner(runner);
111+
96112
mocha.suite.suites.each(function (suite) {
97113
suite.beforeAll(function () {
98114
Test.startSuite(suite.name);

0 commit comments

Comments
 (0)