r88509 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88508‎ | r88509 | r88510 >
Date:09:16, 21 May 2011
Author:hashar
Status:ok (Comments)
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js
@@ -61,13 +61,39 @@
6262 });
6363
6464 test( 'mw.loader', function(){
65 - expect(2);
66 -
67 - ok( location.href.match(/[^#\?]*/) && location.href.match(/[^#\?]*/)[0], true, 'Extracting file path from location' );
 65+ expect(5);
6866
 67+ // Regular expression to extract the path for the QUnit tests
 68+ // Takes into account that tests could be run from a file:// URL
 69+ // by excluding the 'index.html' part from the URL
 70+ var rePath = /(?:[^#\?](?!index.html))*\/?/;
 71+
 72+ // Four assertions to test the above regular expression:
 73+ equal(
 74+ rePath.exec( 'http://path/to/tests/?foobar' )[0],
 75+ "http://path/to/tests/",
 76+ "Extracting path from http URL with query"
 77+ );
 78+ equal(
 79+ rePath.exec( 'http://path/to/tests/#frag' )[0],
 80+ "http://path/to/tests/",
 81+ "Extracting path from http URL with fragment"
 82+ );
 83+ equal(
 84+ rePath.exec( 'file://path/to/tests/index.html?foobar' )[0],
 85+ "file://path/to/tests/",
 86+ "Extracting path from local URL (file://) with query"
 87+ );
 88+ equal(
 89+ rePath.exec( 'file://path/to/tests/index.html#frag' )[0],
 90+ "file://path/to/tests/",
 91+ "Extracting path from local URL (file://) with fragment"
 92+ );
 93+
6994 stop();
70 -
71 - mw.loader.implement( 'is.awesome', [location.href.match(/[^#\?]*/)[0] + 'sample/awesome.js'], {}, {} );
 95+
 96+ var tests_path = rePath.exec( location.href ); // Extract path
 97+ mw.loader.implement( 'is.awesome', [tests_path + 'sample/awesome.js'], {}, {} );
7298 mw.loader.using( 'is.awesome', function(){
7399 start();
74100 deepEqual( window.awesome, true, 'Implementing a module, is the callback timed properly ?');

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88431QUnit reorganization...krinkle21:35, 19 May 2011

Comments

#Comment by Krinkle (talk | contribs)   09:38, 21 May 2011

Thanks!

Status & tagging log