r99232 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99231‎ | r99232 | r99233 >
Date:19:03, 7 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Updated qunit
Modified paths:
  • /trunk/parsers/wikidom/lib/qunit.css (modified) (history)
  • /trunk/parsers/wikidom/lib/qunit.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/qunit.css
@@ -1,5 +1,5 @@
22 /**
3 - * QUnit - A JavaScript Unit Testing Framework
 3+ * QUnit 1.1.0pre - A JavaScript Unit Testing Framework
44 *
55 * http://docs.jquery.com/QUnit
66 *
@@ -186,6 +186,7 @@
187187 color: #710909;
188188 background-color: #fff;
189189 border-left: 26px solid #EE5757;
 190+ white-space: pre;
190191 }
191192
192193 #qunit-tests > li:last-child {
@@ -222,4 +223,4 @@
223224 position: absolute;
224225 top: -10000px;
225226 left: -10000px;
226 -}
\ No newline at end of file
 227+}
Index: trunk/parsers/wikidom/lib/qunit.js
@@ -1,5 +1,5 @@
22 /**
3 - * QUnit - A JavaScript Unit Testing Framework
 3+ * QUnit 1.1.0pre - A JavaScript Unit Testing Framework
44 *
55 * http://docs.jquery.com/QUnit
66 *
@@ -48,7 +48,7 @@
4949 setup: function() {
5050 if (this.module != config.previousModule) {
5151 if ( config.previousModule ) {
52 - QUnit.moduleDone( {
 52+ runLoggingCallbacks('moduleDone', QUnit, {
5353 name: config.previousModule,
5454 failed: config.moduleStats.bad,
5555 passed: config.moduleStats.all - config.moduleStats.bad,
@@ -57,7 +57,7 @@
5858 }
5959 config.previousModule = this.module;
6060 config.moduleStats = { all: 0, bad: 0 };
61 - QUnit.moduleStart( {
 61+ runLoggingCallbacks( 'moduleStart', QUnit, {
6262 name: this.module
6363 } );
6464 }
@@ -71,9 +71,10 @@
7272 extend(this.testEnvironment, this.testEnvironmentArg);
7373 }
7474
75 - QUnit.testStart( {
76 - name: this.testName
77 - } );
 75+ runLoggingCallbacks( 'testStart', QUnit, {
 76+ name: this.testName,
 77+ module: this.module
 78+ });
7879
7980 // allow utility functions to access the current test environment
8081 // TODO why??
@@ -210,8 +211,9 @@
211212 fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset);
212213 }
213214
214 - QUnit.testDone( {
 215+ runLoggingCallbacks( 'testDone', QUnit, {
215216 name: this.testName,
 217+ module: this.module,
216218 failed: bad,
217219 passed: this.assertions.length - bad,
218220 total: this.assertions.length
@@ -310,8 +312,8 @@
311313 result: a,
312314 message: msg
313315 };
314 - msg = escapeHtml(msg);
315 - QUnit.log(details);
 316+ msg = escapeInnerText(msg);
 317+ runLoggingCallbacks( 'log', QUnit, details );
316318 config.current.assertions.push({
317319 result: a,
318320 message: msg
@@ -387,8 +389,8 @@
388390 QUnit.ok(ok, message);
389391 },
390392
391 - start: function() {
392 - config.semaphore--;
 393+ start: function(count) {
 394+ config.semaphore -= count || 1;
393395 if (config.semaphore > 0) {
394396 // don't start until equal number of stop-calls
395397 return;
@@ -416,20 +418,30 @@
417419 }
418420 },
419421
420 - stop: function(timeout) {
421 - config.semaphore++;
 422+ stop: function(count) {
 423+ config.semaphore += count || 1;
422424 config.blocking = true;
423425
424 - if ( timeout && defined.setTimeout ) {
 426+ if ( config.testTimeout && defined.setTimeout ) {
425427 clearTimeout(config.timeout);
426428 config.timeout = window.setTimeout(function() {
427429 QUnit.ok( false, "Test timed out" );
 430+ config.semaphore = 1;
428431 QUnit.start();
429 - }, timeout);
 432+ }, config.testTimeout);
430433 }
431434 }
432435 };
433436
 437+//We want access to the constructor's prototype
 438+(function() {
 439+ function F(){};
 440+ F.prototype = QUnit;
 441+ QUnit = new F();
 442+ //Make F QUnit's constructor so that we can add to the prototype later
 443+ QUnit.constructor = F;
 444+})();
 445+
434446 // Backwards compatibility, deprecated
435447 QUnit.equals = QUnit.equal;
436448 QUnit.same = QUnit.deepEqual;
@@ -453,8 +465,16 @@
454466 // by default, modify document.title when suite is done
455467 altertitle: true,
456468
457 - noglobals: false,
458 - notrycatch: false
 469+ urlConfig: ['noglobals', 'notrycatch'],
 470+
 471+ //logging callback queues
 472+ begin: [],
 473+ done: [],
 474+ log: [],
 475+ testStart: [],
 476+ testDone: [],
 477+ moduleStart: [],
 478+ moduleDone: []
459479 };
460480
461481 // Load paramaters
@@ -472,9 +492,6 @@
473493 // allow just a key to turn on a flag, e.g., test.html?noglobals
474494 current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
475495 urlParams[ current[ 0 ] ] = current[ 1 ];
476 - if ( current[ 0 ] in config ) {
477 - config[ current[ 0 ] ] = current[ 1 ];
478 - }
479496 }
480497 }
481498
@@ -622,10 +639,10 @@
623640 expected: expected
624641 };
625642
626 - message = escapeHtml(message) || (result ? "okay" : "failed");
 643+ message = escapeInnerText(message) || (result ? "okay" : "failed");
627644 message = '<span class="test-message">' + message + "</span>";
628 - expected = escapeHtml(QUnit.jsDump.parse(expected));
629 - actual = escapeHtml(QUnit.jsDump.parse(actual));
 645+ expected = escapeInnerText(QUnit.jsDump.parse(expected));
 646+ actual = escapeInnerText(QUnit.jsDump.parse(actual));
630647 var output = message + '<table><tr class="test-expected"><th>Expected: </th><td><pre>' + expected + '</pre></td></tr>';
631648 if (actual != expected) {
632649 output += '<tr class="test-actual"><th>Result: </th><td><pre>' + actual + '</pre></td></tr>';
@@ -635,12 +652,12 @@
636653 var source = sourceFromStacktrace();
637654 if (source) {
638655 details.source = source;
639 - output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeHtml(source) + '</pre></td></tr>';
 656+ output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeInnerText(source) + '</pre></td></tr>';
640657 }
641658 }
642659 output += "</table>";
643660
644 - QUnit.log(details);
 661+ runLoggingCallbacks( 'log', QUnit, details );
645662
646663 config.current.assertions.push({
647664 result: !!result,
@@ -661,23 +678,28 @@
662679
663680 extend: extend,
664681 id: id,
665 - addEvent: addEvent,
 682+ addEvent: addEvent
 683+});
666684
 685+//QUnit.constructor is set to the empty F() above so that we can add to it's prototype later
 686+//Doing this allows us to tell if the following methods have been overwritten on the actual
 687+//QUnit object, which is a deprecated way of using the callbacks.
 688+extend(QUnit.constructor.prototype, {
667689 // Logging callbacks; all receive a single argument with the listed properties
668690 // run test/logs.html for any related changes
669 - begin: function() {},
 691+ begin: registerLoggingCallback('begin'),
670692 // done: { failed, passed, total, runtime }
671 - done: function() {},
 693+ done: registerLoggingCallback('done'),
672694 // log: { result, actual, expected, message }
673 - log: function() {},
 695+ log: registerLoggingCallback('log'),
674696 // testStart: { name }
675 - testStart: function() {},
 697+ testStart: registerLoggingCallback('testStart'),
676698 // testDone: { name, failed, passed, total }
677 - testDone: function() {},
 699+ testDone: registerLoggingCallback('testDone'),
678700 // moduleStart: { name }
679 - moduleStart: function() {},
 701+ moduleStart: registerLoggingCallback('moduleStart'),
680702 // moduleDone: { name, failed, passed, total }
681 - moduleDone: function() {}
 703+ moduleDone: registerLoggingCallback('moduleDone')
682704 });
683705
684706 if ( typeof document === "undefined" || document.readyState === "complete" ) {
@@ -685,7 +707,7 @@
686708 }
687709
688710 QUnit.load = function() {
689 - QUnit.begin({});
 711+ runLoggingCallbacks( 'begin', QUnit, {} );
690712
691713 // Initialize the config, saving the execution queue
692714 var oldconfig = extend({}, config);
@@ -694,15 +716,19 @@
695717
696718 config.blocking = false;
697719
 720+ var urlConfigHtml = '', len = config.urlConfig.length;
 721+ for ( var i = 0, val; i < len, val = config.urlConfig[i]; i++ ) {
 722+ config[val] = QUnit.urlParams[val];
 723+ urlConfigHtml += '<label><input name="' + val + '" type="checkbox"' + ( config[val] ? ' checked="checked"' : '' ) + '>' + val + '</label>';
 724+ }
 725+
698726 var userAgent = id("qunit-userAgent");
699727 if ( userAgent ) {
700728 userAgent.innerHTML = navigator.userAgent;
701729 }
702730 var banner = id("qunit-header");
703731 if ( banner ) {
704 - banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' +
705 - '<label><input name="noglobals" type="checkbox"' + ( config.noglobals ? ' checked="checked"' : '' ) + '>noglobals</label>' +
706 - '<label><input name="notrycatch" type="checkbox"' + ( config.notrycatch ? ' checked="checked"' : '' ) + '>notrycatch</label>';
 732+ banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' + urlConfigHtml;
707733 addEvent( banner, "change", function( event ) {
708734 var params = {};
709735 params[ event.target.name ] = event.target.checked ? true : undefined;
@@ -761,7 +787,7 @@
762788
763789 // Log the last module results
764790 if ( config.currentModule ) {
765 - QUnit.moduleDone( {
 791+ runLoggingCallbacks( 'moduleDone', QUnit, {
766792 name: config.currentModule,
767793 failed: config.moduleStats.bad,
768794 passed: config.moduleStats.all - config.moduleStats.bad,
@@ -803,7 +829,7 @@
804830 ].join(" ");
805831 }
806832
807 - QUnit.done( {
 833+ runLoggingCallbacks( 'done', QUnit, {
808834 failed: config.stats.bad,
809835 passed: passed,
810836 total: config.stats.all,
@@ -847,20 +873,22 @@
848874 } else if (e.stack) {
849875 // Firefox, Chrome
850876 return e.stack.split("\n")[4];
 877+ } else if (e.sourceURL) {
 878+ // Safari, PhantomJS
 879+ // TODO sourceURL points at the 'throw new Error' line above, useless
 880+ //return e.sourceURL + ":" + e.line;
851881 }
852882 }
853883 }
854884
855 -function escapeHtml(s) {
 885+function escapeInnerText(s) {
856886 if (!s) {
857887 return "";
858888 }
859889 s = s + "";
860 - return s.replace(/[\&"<>\\]/g, function(s) {
 890+ return s.replace(/[\&<>]/g, function(s) {
861891 switch(s) {
862892 case "&": return "&amp;";
863 - case "\\": return "\\\\";
864 - case '"': return '\"';
865893 case "<": return "&lt;";
866894 case ">": return "&gt;";
867895 default: return s;
@@ -970,9 +998,27 @@
971999 document.getElementById( name );
9721000 }
9731001
 1002+function registerLoggingCallback(key){
 1003+ return function(callback){
 1004+ config[key].push( callback );
 1005+ };
 1006+}
 1007+
 1008+// Supports deprecated method of completely overwriting logging callbacks
 1009+function runLoggingCallbacks(key, scope, args) {
 1010+ //debugger;
 1011+ var callbacks;
 1012+ if ( QUnit.hasOwnProperty(key) ) {
 1013+ QUnit[key].call(scope, args);
 1014+ } else {
 1015+ callbacks = config[key];
 1016+ for( var i = 0; i < callbacks.length; i++ ) {
 1017+ callbacks[i].call( scope, args );
 1018+ }
 1019+ }
 1020+}
 1021+
9741022 // Test for equality any JavaScript type.
975 -// Discussions and reference: http://philrathe.com/articles/equiv
976 -// Test suites: http://philrathe.com/tests/equiv
9771023 // Author: Philippe Rathé <prathe@gmail.com>
9781024 QUnit.equiv = function () {
9791025
@@ -1198,10 +1244,10 @@
11991245 if (type == 'function') {
12001246 stack.push(obj);
12011247 var res = parser.call( this, obj, stack );
1202 - stack.pop();
 1248+ stack.pop();
12031249 return res;
1204 - }
1205 - // else
 1250+ }
 1251+ // else
12061252 return (type == 'string') ? parser : this.parsers.error;
12071253 },
12081254 typeOf:function( obj ) {
@@ -1382,13 +1428,13 @@
13831429 */
13841430 QUnit.diff = (function() {
13851431 function diff(o, n) {
1386 - var ns = new Object();
1387 - var os = new Object();
 1432+ var ns = {};
 1433+ var os = {};
13881434
13891435 for (var i = 0; i < n.length; i++) {
13901436 if (ns[n[i]] == null)
13911437 ns[n[i]] = {
1392 - rows: new Array(),
 1438+ rows: [],
13931439 o: null
13941440 };
13951441 ns[n[i]].rows.push(i);
@@ -1397,7 +1443,7 @@
13981444 for (var i = 0; i < o.length; i++) {
13991445 if (os[o[i]] == null)
14001446 os[o[i]] = {
1401 - rows: new Array(),
 1447+ rows: [],
14021448 n: null
14031449 };
14041450 os[o[i]].rows.push(i);
@@ -1503,4 +1549,4 @@
15041550 };
15051551 })();
15061552
1507 -})(this);
\ No newline at end of file
 1553+})(this);

Status & tagging log