Skip to content

Commit 560f349

Browse files
Unify our feature detection for console.log/group.
1 parent 6a99225 commit 560f349

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

test.new/static/js/test_helpers.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11

22
(function () {
33

4+
var CONSOLE_LOG_SUPPORTED = ('console' in window) && console.log;
5+
var CONSOLE_GROUP_SUPPORTED = ('console' in window) && console.group &&
6+
console.groupEnd;
7+
var CONSOLE_LOG_APPLY = true;
8+
49
function info() {
5-
console.log.apply(console, arguments);
10+
if (CONSOLE_LOG_APPLY) {
11+
console.log.apply(console, arguments);
12+
} else {
13+
console.log(arguments);
14+
}
615
}
716

8-
// Fall back when we don't have the console.
9-
// TODO: Find a different way of logging in old IEs.
10-
if (!('console' in window) || !console.log) {
11-
info = function () {};
17+
if (!CONSOLE_LOG_SUPPORTED) {
18+
info = Prototype.emptyFunction;
19+
} else {
20+
try {
21+
console.log.apply(console, [""]);
22+
} catch (e) {
23+
CONSOLE_LOG_APPLY = false;
24+
}
1225
}
13-
window.info = info;
1426

15-
var CONSOLE_GROUP_SUPPORTED = ('console' in window) && console.group &&
16-
console.groupEnd;
27+
window.info = info;
1728

1829
// A function that acts like setTimeout, except with arguments reversed. This
1930
// is far more readable within tests.
@@ -193,6 +204,7 @@
193204
// tests run, then detach them all from the document. Then, before a suite
194205
// runs, its fixtures are reattached, then removed again before the next
195206
// suite runs.
207+
//
196208
window.Test = {
197209
setup: function () {
198210
var body = $(document.body);
@@ -211,6 +223,8 @@
211223
startSuite: function (suite) {
212224
if (CONSOLE_GROUP_SUPPORTED) {
213225
console.group('Suite:', suite);
226+
} else if (CONSOLE_LOG_SUPPORTED) {
227+
console.log('Suite:', suite);
214228
}
215229

216230
if (this.currentFixtures && this.currentFixtures.parentNode) {

0 commit comments

Comments
 (0)