mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
Tests: console log capture utility
This commit is contained in:
parent
d782da411e
commit
5a300998a8
41
test/test.js
41
test/test.js
@ -71,5 +71,46 @@
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
Test console log capture
|
||||
|
||||
1. Only the OpenSeadragon.console logger is touched
|
||||
2. All log messages are stored in window.testLog in arrays keyed on the logger name (e.g. log,
|
||||
warning, error, etc.) as JSON-serialized strings to simplify comparisons
|
||||
3. The captured log arrays have a custom contains() method for ease of testing
|
||||
4. testLog.reset() will clear all of the message arrays, intended for use in test setup routines
|
||||
*/
|
||||
var testConsole = window.testConsole = {},
|
||||
testLog = window.testLog = {
|
||||
log: [],
|
||||
debug: [],
|
||||
info: [],
|
||||
warn: [],
|
||||
error: [],
|
||||
reset: function () {
|
||||
for (var i in testLog) {
|
||||
if (testLog.hasOwnProperty(i) && 'length' in testLog[i]) {
|
||||
testLog[i].length = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (var i in testLog) {
|
||||
if (testLog.hasOwnProperty(i) && testLog[i].push) {
|
||||
testConsole[i] = (function (arr) {
|
||||
return function () {
|
||||
var args = Array.prototype.slice.call(arguments, 0); // Coerce to true Array
|
||||
arr.push(JSON.stringify(args)); // Store as JSON to avoid tedious array-equality tests
|
||||
};
|
||||
})(testLog[i]);
|
||||
|
||||
testLog[i].contains = function (needle) {
|
||||
return this.indexOf(needle) > -1;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
OpenSeadragon.console = testConsole;
|
||||
})();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user