Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js |
— | — | @@ -61,13 +61,39 @@ |
62 | 62 | }); |
63 | 63 | |
64 | 64 | 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); |
68 | 66 | |
| 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 | + |
69 | 94 | 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'], {}, {} ); |
72 | 98 | mw.loader.using( 'is.awesome', function(){ |
73 | 99 | start(); |
74 | 100 | deepEqual( window.awesome, true, 'Implementing a module, is the callback timed properly ?'); |