r101535 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101534‎ | r101535 | r101536 >
Date:21:45, 1 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Upgraded QUnit and removed Synth tests which are not being used and are badly broken.
Modified paths:
  • /trunk/parsers/wikidom/lib/qunit.css (modified) (history)
  • /trunk/parsers/wikidom/lib/qunit.js (modified) (history)
  • /trunk/parsers/wikidom/tests/annotations/index.html (modified) (history)
  • /trunk/parsers/wikidom/tests/hype/index.html (modified) (history)
  • /trunk/parsers/wikidom/tests/serializers/index.html (modified) (history)
  • /trunk/parsers/wikidom/tests/synth (deleted) (history)
  • /trunk/parsers/wikidom/tests/transactions/index.html (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/index.html
@@ -8,8 +8,10 @@
99 <body>
1010 <h1 id="qunit-header">Hype Tests</h1>
1111 <h2 id="qunit-banner"></h2>
 12+ <div id="qunit-testrunner-toolbar"></div>
1213 <h2 id="qunit-userAgent"></h2>
1314 <ol id="qunit-tests"></ol>
 15+ <div id="qunit-fixture">test markup</div>
1416 <script src="../../lib/jquery.js"></script>
1517 <script src="../../lib/qunit.js"></script>
1618 <script src="../../lib/hype/es.js"></script>
Index: trunk/parsers/wikidom/tests/transactions/index.html
@@ -8,8 +8,10 @@
99 <body>
1010 <h1 id="qunit-header">Transaction Tests</h1>
1111 <h2 id="qunit-banner"></h2>
 12+ <div id="qunit-testrunner-toolbar"></div>
1213 <h2 id="qunit-userAgent"></h2>
1314 <ol id="qunit-tests"></ol>
 15+ <div id="qunit-fixture">test markup</div>
1416 <script src="../../lib/es/es.js"></script>
1517 <script src="../../lib/es/es.EventEmitter.js"></script>
1618 <script src="../../lib/es/es.Content.js"></script>
Index: trunk/parsers/wikidom/tests/serializers/index.html
@@ -8,8 +8,10 @@
99 <body>
1010 <h1 id="qunit-header">Wikidom Tests</h1>
1111 <h2 id="qunit-banner"></h2>
 12+ <div id="qunit-testrunner-toolbar"></div>
1213 <h2 id="qunit-userAgent"></h2>
1314 <ol id="qunit-tests"></ol>
 15+ <div id="qunit-fixture">test markup</div>
1416 <script src="../../lib/qunit.js"></script>
1517 <script src="../../lib/jquery.js"></script>
1618 <script src="../../lib/es/es.js"></script>
Index: trunk/parsers/wikidom/tests/annotations/index.html
@@ -8,8 +8,10 @@
99 <body>
1010 <h1 id="qunit-header">Wikidom Tests</h1>
1111 <h2 id="qunit-banner"></h2>
 12+ <div id="qunit-testrunner-toolbar"></div>
1213 <h2 id="qunit-userAgent"></h2>
1314 <ol id="qunit-tests"></ol>
 15+ <div id="qunit-fixture">test markup</div>
1416 <script src="../../lib/es/es.js"></script>
1517 <script src="../../lib/es/es.EventEmitter.js"></script>
1618 <script src="../../lib/es/es.Content.js"></script>
Index: trunk/parsers/wikidom/lib/qunit.css
@@ -1,5 +1,5 @@
22 /**
3 - * QUnit 1.1.0pre - A JavaScript Unit Testing Framework
 3+ * QUnit 1.2.0pre - A JavaScript Unit Testing Framework
44 *
55 * http://docs.jquery.com/QUnit
66 *
Index: trunk/parsers/wikidom/lib/qunit.js
@@ -1,5 +1,5 @@
22 /**
3 - * QUnit 1.1.0pre - A JavaScript Unit Testing Framework
 3+ * QUnit 1.2.0pre - A JavaScript Unit Testing Framework
44 *
55 * http://docs.jquery.com/QUnit
66 *
@@ -21,7 +21,9 @@
2222 })()
2323 };
2424
25 -var testId = 0;
 25+var testId = 0,
 26+ toString = Object.prototype.toString,
 27+ hasOwn = Object.prototype.hasOwnProperty;
2628
2729 var Test = function(name, testName, expected, testEnvironmentArg, async, callback) {
2830 this.name = name;
@@ -91,6 +93,7 @@
9294 }
9395 },
9496 run: function() {
 97+ config.current = this;
9598 if ( this.async ) {
9699 QUnit.stop();
97100 }
@@ -109,11 +112,12 @@
110113
111114 // Restart the tests if they're blocking
112115 if ( config.blocking ) {
113 - start();
 116+ QUnit.start();
114117 }
115118 }
116119 },
117120 teardown: function() {
 121+ config.current = this;
118122 try {
119123 this.testEnvironment.teardown.call(this.testEnvironment);
120124 checkPollution();
@@ -122,7 +126,8 @@
123127 }
124128 },
125129 finish: function() {
126 - if ( this.expected && this.expected != this.assertions.length ) {
 130+ config.current = this;
 131+ if ( this.expected != null && this.expected != this.assertions.length ) {
127132 QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" );
128133 }
129134
@@ -245,7 +250,7 @@
246251 if (bad) {
247252 run();
248253 } else {
249 - synchronize(run);
 254+ synchronize(run, true);
250255 };
251256 }
252257
@@ -262,7 +267,7 @@
263268 asyncTest: function(testName, expected, callback) {
264269 if ( arguments.length === 2 ) {
265270 callback = expected;
266 - expected = 0;
 271+ expected = null;
267272 }
268273
269274 QUnit.test(testName, expected, callback, true);
@@ -410,11 +415,11 @@
411416 }
412417
413418 config.blocking = false;
414 - process();
 419+ process(true);
415420 }, 13);
416421 } else {
417422 config.blocking = false;
418 - process();
 423+ process(true);
419424 }
420425 },
421426
@@ -607,8 +612,7 @@
608613 return "null";
609614 }
610615
611 - var type = Object.prototype.toString.call( obj )
612 - .match(/^\[object\s(.*)\]$/)[1] || '';
 616+ var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || '';
613617
614618 switch (type) {
615619 case 'Number':
@@ -670,6 +674,9 @@
671675 var querystring = "?",
672676 key;
673677 for ( key in params ) {
 678+ if ( !hasOwn.call( params, key ) ) {
 679+ continue;
 680+ }
674681 querystring += encodeURIComponent( key ) + "=" +
675682 encodeURIComponent( params[ key ] ) + "&";
676683 }
@@ -782,6 +789,17 @@
783790
784791 addEvent(window, "load", QUnit.load);
785792
 793+// addEvent(window, "error") gives us a useless event object
 794+window.onerror = function( message, file, line ) {
 795+ if ( QUnit.config.current ) {
 796+ ok( false, message + ", " + file + ":" + line );
 797+ } else {
 798+ test( "global failure", function() {
 799+ ok( false, message + ", " + file + ":" + line );
 800+ });
 801+ }
 802+};
 803+
786804 function done() {
787805 config.autorun = true;
788806
@@ -896,26 +914,30 @@
897915 });
898916 }
899917
900 -function synchronize( callback ) {
 918+function synchronize( callback, last ) {
901919 config.queue.push( callback );
902920
903921 if ( config.autorun && !config.blocking ) {
904 - process();
 922+ process(last);
905923 }
906924 }
907925
908 -function process() {
909 - var start = (new Date()).getTime();
 926+function process( last ) {
 927+ var start = new Date().getTime();
 928+ config.depth = config.depth ? config.depth + 1 : 1;
910929
911930 while ( config.queue.length && !config.blocking ) {
912 - if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) {
 931+ if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) {
913932 config.queue.shift()();
914933 } else {
915 - window.setTimeout( process, 13 );
 934+ window.setTimeout( function(){
 935+ process( last );
 936+ }, 13 );
916937 break;
917938 }
918939 }
919 - if (!config.blocking && !config.queue.length) {
 940+ config.depth--;
 941+ if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) {
920942 done();
921943 }
922944 }
@@ -925,6 +947,9 @@
926948
927949 if ( config.noglobals ) {
928950 for ( var key in window ) {
 951+ if ( !hasOwn.call( window, key ) ) {
 952+ continue;
 953+ }
929954 config.pollution.push( key );
930955 }
931956 }
@@ -975,7 +1000,9 @@
9761001 for ( var prop in b ) {
9771002 if ( b[prop] === undefined ) {
9781003 delete a[prop];
979 - } else {
 1004+
 1005+ // Avoid "Member not found" error in IE8 caused by setting window.constructor
 1006+ } else if ( prop !== "constructor" || a !== window ) {
9801007 a[prop] = b[prop];
9811008 }
9821009 }
@@ -1268,10 +1295,13 @@
12691296 type = "document";
12701297 } else if (obj.nodeType) {
12711298 type = "node";
1272 - } else if (Object.prototype.toString.call( obj ) == "[object Array]") {
 1299+ } else if (
 1300+ // native arrays
 1301+ toString.call( obj ) === "[object Array]" ||
 1302+ // NodeList objects
 1303+ ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
 1304+ ) {
12731305 type = "array";
1274 - } else if (Object.prototype.toString.call( obj ) == "[object NodeList]") {
1275 - type = "array";
12761306 } else {
12771307 type = typeof obj;
12781308 }
@@ -1452,6 +1482,9 @@
14531483 }
14541484
14551485 for (var i in ns) {
 1486+ if ( !hasOwn.call( ns, i ) ) {
 1487+ continue;
 1488+ }
14561489 if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) {
14571490 n[ns[i].rows[0]] = {
14581491 text: n[ns[i].rows[0]],

Status & tagging log