From 82c8894c35d5f28c1cd3757b9474f72f31b4b4d1 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sat, 21 May 2011 09:16:59 +0000 Subject: [PATCH] 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 --- .../suites/resources/mediawiki/mediawiki.js | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.js b/tests/qunit/suites/resources/mediawiki/mediawiki.js index bcd8a5a5be..24c6c92488 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.js @@ -61,13 +61,39 @@ test( 'mw.message / mw.msg / mw.messages', function(){ }); 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 ?'); -- 2.20.1