/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/doc/example-jsunit/jsunit/app/jsUnitTracer.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs · JavaScript · 102 lines · 87 code · 15 blank · 0 comment · 16 complexity · cd02a42fc0ac84eafd02c95b22321ee5 MD5 · raw file

  1. var TRACE_LEVEL_NONE = new JsUnitTraceLevel(0, null);
  2. var TRACE_LEVEL_WARNING = new JsUnitTraceLevel(1, "#FF0000");
  3. var TRACE_LEVEL_INFO = new JsUnitTraceLevel(2, "#009966");
  4. var TRACE_LEVEL_DEBUG = new JsUnitTraceLevel(3, "#0000FF");
  5. function JsUnitTracer(testManager) {
  6. this._testManager = testManager;
  7. this._traceWindow = null;
  8. this.popupWindowsBlocked = false;
  9. }
  10. JsUnitTracer.prototype.initialize = function() {
  11. if (this._traceWindow != null && top.testManager.closeTraceWindowOnNewRun.checked)
  12. this._traceWindow.close();
  13. this._traceWindow = null;
  14. }
  15. JsUnitTracer.prototype.finalize = function() {
  16. if (this._traceWindow != null) {
  17. this._traceWindow.document.write('<\/body>\n<\/html>');
  18. this._traceWindow.document.close();
  19. }
  20. }
  21. JsUnitTracer.prototype.warn = function() {
  22. this._trace(arguments[0], arguments[1], TRACE_LEVEL_WARNING);
  23. }
  24. JsUnitTracer.prototype.inform = function() {
  25. this._trace(arguments[0], arguments[1], TRACE_LEVEL_INFO);
  26. }
  27. JsUnitTracer.prototype.debug = function() {
  28. this._trace(arguments[0], arguments[1], TRACE_LEVEL_DEBUG);
  29. }
  30. JsUnitTracer.prototype._trace = function(message, value, traceLevel) {
  31. if (!top.shouldSubmitResults() && this._getChosenTraceLevel().matches(traceLevel)) {
  32. var traceString = message;
  33. if (value)
  34. traceString += ': ' + value;
  35. var prefix = this._testManager.getTestFileName() + ":" +
  36. this._testManager.getTestFunctionName() + " - ";
  37. this._writeToTraceWindow(prefix, traceString, traceLevel);
  38. }
  39. }
  40. JsUnitTracer.prototype._getChosenTraceLevel = function() {
  41. var levelNumber = eval(top.testManager.traceLevel.value);
  42. return traceLevelByLevelNumber(levelNumber);
  43. }
  44. JsUnitTracer.prototype._writeToTraceWindow = function(prefix, traceString, traceLevel) {
  45. var htmlToAppend = '<p class="jsUnitDefault">' + prefix + '<font color="' + traceLevel.getColor() + '">' + traceString + '</font><\/p>\n';
  46. this._getTraceWindow().document.write(htmlToAppend);
  47. }
  48. JsUnitTracer.prototype._getTraceWindow = function() {
  49. if (this._traceWindow == null && !top.shouldSubmitResults() && !this.popupWindowsBlocked) {
  50. this._traceWindow = window.open('', '', 'width=600, height=350,status=no,resizable=yes,scrollbars=yes');
  51. if (!this._traceWindow)
  52. this.popupWindowsBlocked = true;
  53. else {
  54. var resDoc = this._traceWindow.document;
  55. resDoc.write('<html>\n<head>\n<link rel="stylesheet" href="css/jsUnitStyle.css">\n<title>Tracing - JsUnit<\/title>\n<head>\n<body>');
  56. resDoc.write('<h2>Tracing - JsUnit<\/h2>\n');
  57. resDoc.write('<p class="jsUnitDefault"><i>(Traces are color coded: ');
  58. resDoc.write('<font color="' + TRACE_LEVEL_WARNING.getColor() + '">Warning</font> - ');
  59. resDoc.write('<font color="' + TRACE_LEVEL_INFO.getColor() + '">Information</font> - ');
  60. resDoc.write('<font color="' + TRACE_LEVEL_DEBUG.getColor() + '">Debug</font>');
  61. resDoc.write(')</i></p>');
  62. }
  63. }
  64. return this._traceWindow;
  65. }
  66. if (xbDEBUG.on) {
  67. xbDebugTraceObject('window', 'JsUnitTracer');
  68. }
  69. function JsUnitTraceLevel(levelNumber, color) {
  70. this._levelNumber = levelNumber;
  71. this._color = color;
  72. }
  73. JsUnitTraceLevel.prototype.matches = function(anotherTraceLevel) {
  74. return this._levelNumber >= anotherTraceLevel._levelNumber;
  75. }
  76. JsUnitTraceLevel.prototype.getColor = function() {
  77. return this._color;
  78. }
  79. function traceLevelByLevelNumber(levelNumber) {
  80. switch (levelNumber) {
  81. case 0: return TRACE_LEVEL_NONE;
  82. case 1: return TRACE_LEVEL_WARNING;
  83. case 2: return TRACE_LEVEL_INFO;
  84. case 3: return TRACE_LEVEL_DEBUG;
  85. }
  86. return null;
  87. }