http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88509

Revision: 88509
Author:   hashar
Date:     2011-05-21 09:16:59 +0000 (Sat, 21 May 2011)
Log Message:
-----------
Fix the mw.loader when running test with a file:// URL

When running the tests using a local url, the href will include index.html
which was not stripped by the regular expression.  This patch capture path
tokens which are not followed by 'index.html' (regexp lookahead).

Let us run tests using file://path/tests/qunit/index.html

Modified Paths:
--------------
    trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js

Modified: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js
===================================================================
--- trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js    
2011-05-21 07:57:35 UTC (rev 88508)
+++ trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js    
2011-05-21 09:16:59 UTC (rev 88509)
@@ -61,13 +61,39 @@
 });
 
 test( 'mw.loader', function(){
-       expect(2);
-       
-       ok( location.href.match(/[^#\?]*/) && 
location.href.match(/[^#\?]*/)[0], true, 'Extracting file path from location' );
+       expect(5);
 
+       // Regular expression to extract the path for the QUnit tests   
+       // Takes into account that tests could be run from a file:// URL
+       // by excluding the 'index.html' part from the URL
+       var rePath = /(?:[^#\?](?!index.html))*\/?/;
+
+       // Four assertions to test the above regular expression:
+       equal(
+               rePath.exec( 'http://path/to/tests/?foobar' )[0],
+               "http://path/to/tests/";,
+               "Extracting path from http URL with query"
+               );
+       equal(
+               rePath.exec( 'http://path/to/tests/#frag' )[0],
+               "http://path/to/tests/";,
+               "Extracting path from http URL with fragment"
+               );
+       equal(
+               rePath.exec( 'file://path/to/tests/index.html?foobar' )[0],
+               "file://path/to/tests/",
+               "Extracting path from local URL (file://) with query"
+               );
+       equal(
+               rePath.exec( 'file://path/to/tests/index.html#frag' )[0],
+               "file://path/to/tests/",
+               "Extracting path from local URL (file://) with fragment"
+               );
+
        stop();
-       
-       mw.loader.implement( 'is.awesome', [location.href.match(/[^#\?]*/)[0] + 
'sample/awesome.js'], {}, {} );
+
+       var tests_path = rePath.exec( location.href ); // Extract path
+       mw.loader.implement( 'is.awesome', [tests_path + 'sample/awesome.js'], 
{}, {} );
        mw.loader.using( 'is.awesome', function(){
                start();
                deepEqual( window.awesome, true, 'Implementing a module, is the 
callback timed properly ?');


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to