r88256 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88255‎ | r88256 | r88257 >
Date:18:18, 16 May 2011
Author:krinkle
Status:ok
Tags:
Comment:
* Changed load order in QUnit to mirror the order in MediaWiki itself.
* Added testswarm.inject.js to SVN (Follow-up r87899)
Modified paths:
  • /trunk/phase3/resources/test/index.html (modified) (history)
  • /trunk/phase3/resources/test/testswarm.inject.js (added) (history)

Diff [purge]

Index: trunk/phase3/resources/test/testswarm.inject.js
@@ -0,0 +1,349 @@
 2+/*
 3+ Copyright (c) 2009 John Resig
 4+
 5+ Permission is hereby granted, free of charge, to any person
 6+ obtaining a copy of this software and associated documentation
 7+ files (the "Software"), to deal in the Software without
 8+ restriction, including without limitation the rights to use,
 9+ copy, modify, merge, publish, distribute, sublicense, and/or sell
 10+ copies of the Software, and to permit persons to whom the
 11+ Software is furnished to do so, subject to the following
 12+ conditions:
 13+
 14+ The above copyright notice and this permission notice shall be
 15+ included in all copies or substantial portions of the Software.
 16+
 17+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 18+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 19+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 20+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 21+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 22+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 23+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 24+ OTHER DEALINGS IN THE SOFTWARE.
 25+
 26+*/
 27+(function(){
 28+
 29+ var DEBUG = false;
 30+
 31+ var doPost = false;
 32+
 33+ try {
 34+ doPost = !!window.top.postMessage;
 35+ } catch(e){}
 36+
 37+ var search = window.location.search,
 38+ url, index;
 39+ if( ( index = search.indexOf( "swarmURL=" ) ) != -1 )
 40+ url = decodeURIComponent( search.slice( index + 9 ) );
 41+
 42+ if ( !DEBUG && (!url || url.indexOf("http") !== 0) ) {
 43+ return;
 44+ }
 45+
 46+ var submitTimeout = 5;
 47+
 48+ var curHeartbeat;
 49+ var beatRate = 20;
 50+
 51+ // Expose the TestSwarm API
 52+ window.TestSwarm = {
 53+ submit: submit,
 54+ heartbeat: function(){
 55+ if ( curHeartbeat ) {
 56+ clearTimeout( curHeartbeat );
 57+ }
 58+
 59+ curHeartbeat = setTimeout(function(){
 60+ submit({ fail: -1, total: -1 });
 61+ }, beatRate * 1000);
 62+ },
 63+ serialize: function(){
 64+ return trimSerialize();
 65+ }
 66+ };
 67+
 68+ // Prevent careless things from executing
 69+ window.print = window.confirm = window.alert = window.open = function(){};
 70+
 71+ window.onerror = function(e){
 72+ document.body.appendChild( document.createTextNode( "ERROR: " + e ));
 73+ submit({ fail: 0, error: 1, total: 1 });
 74+ return false;
 75+ };
 76+
 77+ // QUnit (jQuery)
 78+ // http://docs.jquery.com/QUnit
 79+ if ( typeof QUnit !== "undefined" ) {
 80+ QUnit.done = function(results){
 81+ submit({
 82+ fail: results.failed,
 83+ error: 0,
 84+ total: results.total
 85+ });
 86+ };
 87+
 88+ QUnit.log = window.TestSwarm.heartbeat;
 89+ window.TestSwarm.heartbeat();
 90+
 91+ window.TestSwarm.serialize = function(){
 92+ // Clean up the HTML (remove any un-needed test markup)
 93+ remove("nothiddendiv");
 94+ remove("loadediframe");
 95+ remove("dl");
 96+ remove("main");
 97+
 98+ // Show any collapsed results
 99+ var ol = document.getElementsByTagName("ol");
 100+ for ( var i = 0; i < ol.length; i++ ) {
 101+ ol[i].style.display = "block";
 102+ }
 103+
 104+ return trimSerialize();
 105+ };
 106+
 107+ // UnitTestJS (Prototype, Scriptaculous)
 108+ // http://github.com/tobie/unittest_js/tree/master
 109+ } else if ( typeof Test !== "undefined" && Test && Test.Unit && Test.Unit.runners ) {
 110+ var total_runners = Test.Unit.runners.length, cur_runners = 0;
 111+ var total = 0, fail = 0, error = 0;
 112+
 113+ for (var i = 0; i < Test.Unit.runners.length; i++) (function(i){
 114+ var finish = Test.Unit.runners[i].finish;
 115+ Test.Unit.runners[i].finish = function(){
 116+ finish.call( this );
 117+
 118+ var results = this.getResult();
 119+ total += results.assertions;
 120+ fail += results.failures;
 121+ error += results.errors;
 122+
 123+ if ( ++cur_runners === total_runners ) {
 124+ submit({
 125+ fail: fail,
 126+ error: error,
 127+ total: total
 128+ });
 129+ }
 130+ };
 131+ })(i);
 132+
 133+ // JSSpec (MooTools)
 134+ // http://jania.pe.kr/aw/moin.cgi/JSSpec
 135+ } else if ( typeof JSSpec !== "undefined" && JSSpec && JSSpec.Logger ) {
 136+ var onRunnerEnd = JSSpec.Logger.prototype.onRunnerEnd;
 137+ JSSpec.Logger.prototype.onRunnerEnd = function(){
 138+ onRunnerEnd.call(this);
 139+
 140+ // Show any collapsed results
 141+ var ul = document.getElementsByTagName("ul");
 142+ for ( var i = 0; i < ul.length; i++ ) {
 143+ ul[i].style.display = "block";
 144+ }
 145+
 146+ submit({
 147+ fail: JSSpec.runner.getTotalFailures(),
 148+ error: JSSpec.runner.getTotalErrors(),
 149+ total: JSSpec.runner.totalExamples
 150+ });
 151+ };
 152+
 153+ window.TestSwarm.serialize = function(){
 154+ // Show any collapsed results
 155+ var ul = document.getElementsByTagName("ul");
 156+ for ( var i = 0; i < ul.length; i++ ) {
 157+ ul[i].style.display = "block";
 158+ }
 159+
 160+ return trimSerialize();
 161+ };
 162+
 163+ // JSUnit
 164+ // http://www.jsunit.net/
 165+ // Note: Injection file must be included before the frames
 166+ // are document.write()d into the page.
 167+ } else if ( typeof JsUnitTestManager !== "undefined" ) {
 168+ var _done = JsUnitTestManager.prototype._done;
 169+ JsUnitTestManager.prototype._done = function(){
 170+ _done.call(this);
 171+
 172+ submit({
 173+ fail: this.failureCount,
 174+ error: this.errorCount,
 175+ total: this.totalCount
 176+ });
 177+ };
 178+
 179+ window.TestSwarm.serialize = function(){
 180+ return "<pre>" + this.log.join("\n") + "</pre>";
 181+ };
 182+
 183+ // Selenium Core
 184+ // http://seleniumhq.org/projects/core/
 185+ } else if ( typeof SeleniumTestResult !== "undefined" && typeof LOG !== "undefined" ) {
 186+ // Completely overwrite the postback
 187+ SeleniumTestResult.prototype.post = function(){
 188+ submit({
 189+ fail: this.metrics.numCommandFailures,
 190+ error: this.metrics.numCommandErrors,
 191+ total: this.metrics.numCommandPasses + this.metrics.numCommandFailures + this.metrics.numCommandErrors
 192+ });
 193+ };
 194+
 195+ window.TestSwarm.serialize = function(){
 196+ var results = [];
 197+ while ( LOG.pendingMessages.length ) {
 198+ var msg = LOG.pendingMessages.shift();
 199+ results.push( msg.type + ": " + msg.msg );
 200+ }
 201+
 202+ return "<pre>" + results.join("\n") + "</pre>";
 203+ };
 204+
 205+ // Dojo Objective Harness
 206+ // http://docs.dojocampus.org/quickstart/doh
 207+ } else if ( typeof doh !== "undefined" && doh._report ) {
 208+ var _report = doh._report;
 209+ doh._report = function(){
 210+ _report.apply(this, arguments);
 211+
 212+ submit({
 213+ fail: doh._failureCount,
 214+ error: doh._errorCount,
 215+ total: doh._testCount
 216+ });
 217+ };
 218+
 219+ window.TestSwarm.serialize = function(){
 220+ return "<pre>" + document.getElementById("logBody").innerHTML + "</pre>";
 221+ };
 222+ // Screw.Unit
 223+ // git://github.com/nathansobo/screw-unit.git
 224+ } else if ( typeof Screw !== "undefined" && typeof jQuery !== 'undefined' && Screw && Screw.Unit ) {
 225+ $(Screw).bind("after", function() {
 226+ var passed = $('.passed').length;
 227+ var failed = $('.failed').length;
 228+ submit({
 229+ fail: failed,
 230+ error: 0,
 231+ total: failed + passed
 232+ });
 233+ });
 234+
 235+ $(Screw).bind("loaded", function() {
 236+ $('.it')
 237+ .bind("passed", window.TestSwarm.heartbeat)
 238+ .bind("failed", window.TestSwarm.heartbeat);
 239+ window.TestSwarm.heartbeat();
 240+ });
 241+
 242+ window.TestSwarm.serialize = function(){
 243+ return trimSerialize();
 244+ };
 245+ }
 246+
 247+ function trimSerialize(doc) {
 248+ doc = doc || document;
 249+
 250+ var scripts = doc.getElementsByTagName("script");
 251+ while ( scripts.length ) {
 252+ remove( scripts[0] );
 253+ }
 254+
 255+ var root = window.location.href.replace(/(https?:\/\/.*?)\/.*/, "$1");
 256+ var cur = window.location.href.replace(/[^\/]*$/, "");
 257+
 258+ var links = doc.getElementsByTagName("link");
 259+ for ( var i = 0; i < links.length; i++ ) {
 260+ var href = links[i].href;
 261+ if ( href.indexOf("/") === 0 ) {
 262+ href = root + href;
 263+ } else if ( !/^https?:\/\//.test( href ) ) {
 264+ href = cur + href;
 265+ }
 266+ links[i].href = href;
 267+ }
 268+
 269+ return ("<html>" + doc.documentElement.innerHTML + "</html>")
 270+ .replace(/\s+/g, " ");
 271+ }
 272+
 273+ function remove(elem){
 274+ if ( typeof elem === "string" ) {
 275+ elem = document.getElementById( elem );
 276+ }
 277+
 278+ if ( elem ) {
 279+ elem.parentNode.removeChild( elem );
 280+ }
 281+ }
 282+
 283+ function submit(params){
 284+ if ( curHeartbeat ) {
 285+ clearTimeout( curHeartbeat );
 286+ }
 287+
 288+ var paramItems = (url.split("?")[1] || "").split("&");
 289+
 290+ for ( var i = 0; i < paramItems.length; i++ ) {
 291+ if ( paramItems[i] ) {
 292+ var parts = paramItems[i].split("=");
 293+ if ( !params[ parts[0] ] ) {
 294+ params[ parts[0] ] = parts[1];
 295+ }
 296+ }
 297+ }
 298+
 299+ if ( !params.state ) {
 300+ params.state = "saverun";
 301+ }
 302+
 303+ if ( !params.results ) {
 304+ params.results = window.TestSwarm.serialize();
 305+ }
 306+
 307+ if ( doPost ) {
 308+ // Build Query String
 309+ var query = "";
 310+
 311+ for ( var i in params ) {
 312+ query += ( query ? "&" : "" ) + i + "=" +
 313+ encodeURIComponent(params[i]);
 314+ }
 315+
 316+ if ( DEBUG ) {
 317+ alert( query );
 318+ } else {
 319+ window.top.postMessage( query, "*" );
 320+ }
 321+
 322+ } else {
 323+ var form = document.createElement("form");
 324+ form.action = url;
 325+ form.method = "POST";
 326+
 327+ for ( var i in params ) {
 328+ var input = document.createElement("input");
 329+ input.type = "hidden";
 330+ input.name = i;
 331+ input.value = params[i];
 332+ form.appendChild( input );
 333+ }
 334+
 335+ if ( DEBUG ) {
 336+ alert( form.innerHTML );
 337+ } else {
 338+
 339+ // Watch for the result submission timing out
 340+ setTimeout(function(){
 341+ submit( params );
 342+ }, submitTimeout * 1000);
 343+
 344+ document.body.appendChild( form );
 345+ form.submit();
 346+ }
 347+ }
 348+ }
 349+
 350+})();
Property changes on: trunk/phase3/resources/test/testswarm.inject.js
___________________________________________________________________
Added: svn:eol-style
1351 + native
Index: trunk/phase3/resources/test/index.html
@@ -4,15 +4,19 @@
55 <title>MediaWiki JavaScript Test Suite</title>
66
77 <!-- MediaWiki Modules -->
8 - <meta name="ResourceLoaderDynamicStyles" content="" />
9 -
 8+ <script>
 9+ function startUp(){
 10+ mw.config = new mw.Map( false );
 11+ }
 12+ </script>
1013 <script src="../jquery/jquery.js"></script>
11 -
12 - <script> function startUp(){} </script>
1314 <script src="../mediawiki/mediawiki.js"></script>
14 - <script> mw.config = new mw.Map( false ); </script>
1515 <script src="../mediawiki/mediawiki.user.js"></script>
1616
 17+ <script>
 18+ mw.user.options.set({"skin": "vector"});
 19+ </script>
 20+
1721 <script src="../jquery/jquery.checkboxShiftClick.js"></script>
1822 <script src="../jquery/jquery.client.js"></script>
1923 <script src="../jquery/jquery.cookie.js"></script>
@@ -22,22 +26,24 @@
2327 <script src="../mediawiki.util/mediawiki.util.js"></script>
2428
2529 <script src="../jquery/jquery.colorUtil.js"></script>
26 -
 30+
 31+ <meta name="ResourceLoaderDynamicStyles" content="" />
 32+
2733 <!-- QUnit dependancies and scripts -->
2834 <link rel="stylesheet" href="../jquery/jquery.qunit.css" />
2935 <script src="../jquery/jquery.qunit.js"></script>
3036
31 - <!-- Your tests styles go here -->
 37+ <!-- Custom CSS used for tests -->
3238 <link rel="stylesheet" href="unit/main.css" />
3339
34 - <!-- Your test suites go here -->
 40+ <!-- Load test suitss -->
3541 <script src="unit/mediawiki/mediawiki.js"></script>
3642 <script src="unit/mediawiki/mediawiki.user.js"></script>
3743 <script src="unit/mediawiki.util/mediawiki.util.js"></script>
3844 <script src="unit/jquery/jquery.colorUtil.js"></script>
3945
4046 <!-- TestSwarm -->
41 - <script src="http://toolserver.org/~krinkle/testswarm/js/inject.js"></script>
 47+ <script src="testswarm.inject.js"></script>
4248 </head>
4349 <body>
4450 <h1 id="qunit-header">MediaWiki JavaScript Test Suite</h1>

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87899Follow-up r87898: Using real pathkrinkle06:13, 12 May 2011

Status & tagging log