<script>
function startUp(){
mw.config = new mw.Map( false );
+
+ /**
+ * Guess wgScriptPath (for access to /tests/qunit/data/)
+ */
+
+ // 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))*\/?/;
+
+ // Extract path to /tests/qunit/
+ var qunitTestsPath = rePath.exec( location.href )[0];
+
+ // Traverse up to script path
+ var pathParts = qunitTestsPath.split( '/' );
+ pathParts.pop(); pathParts.pop(); pathParts.pop();
+ var scriptPath = pathParts.join( '/' );
+
+ mw.config.set( 'wgScriptPath', scriptPath );
}
</script>
});
test( 'mw.loader', function() {
- 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"
- );
+ expect(1);
// Asynchronous ahead
stop(5000);
- // Extract path
- var tests_path = rePath.exec( location.href );
-
- mw.loader.implement( 'is.awesome', [QUnit.fixurl( tests_path + 'data/defineTestCallback.js' )], {}, {} );
+ mw.loader.implement( 'is.awesome', [QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/defineTestCallback.js' )], {}, {} );
mw.loader.using( 'is.awesome', function() {
test( 'wikiScript', function() {
expect(2);
+ var prevConfig = mw.config.get([ 'wgScript', 'wgScriptPath', 'wgScriptExtension' ]);
mw.config.set({
'wgScript': '/w/index.php',
'wgScriptPath': '/w',
equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' );
equal( mw.util.wikiScript( 'api' ), '/w/api.php', 'API path' );
+ // Restore mw.config
+ mw.config.set( prevConfig );
});
test( 'addCSS', function() {