Add an 'export' subpage to SpecialJavaScriptTest which allows one to request a self-sufficient JavaScript payload that will bootstrap a ResourceLoader client and load the test suites. This is needed for using Karma (which only loads JavaScript, no full html pages). As such elements from the Skin and OutputPage will not exist. While all QUnit tests in MediaWiki core and most extensions I've seen already use #qunit-fixture, this is now required. This to prevent leakage of elements from one test to another, but it also prevents tests from depending on elements provided by the server. While the Karma setup is still in the pipeline (might land before this commit loses WIP status), for now this can be tested via the 'Special:JavaScriptTest/qunit/plain' subpage. Refactor: * Use HTTP status code 404 in the response for "noframework". * Simplify HTML footprint by using <div id="qunit"> instead of hardcoding the full structure. This feature was added to QUnit since v1.3.0 (Feb 2012), we're using v1.14.0 (Jan 2014). QUnit's header is automatically derived from document.title. * Remove redundant addModules() for 'test.mediawiki.qunit.testrunner'. This is already added by default. * Move allowClickjacking() call so that it applies to other modes as well. The exported javascript needs to have wgBreakFrame set to false so that test runners can frame it. * Change mediawiki.special.javaScriptTest to not depend on QUnit. It caused QUnit to load on error pages. And in theory the page is suited for other frameworks and shouldn't load QUnit this way. Bug: T74063 Change-Id: I3d4d0df43bb426d9579eb0349b8b5477281a7cfc
37 lines
1 KiB
JavaScript
37 lines
1 KiB
JavaScript
/*!
|
|
* JavaScript for Special:JavaScriptTest
|
|
*/
|
|
( function ( mw, $ ) {
|
|
$( function () {
|
|
|
|
// Create useskin dropdown menu and reload onchange to the selected skin
|
|
// (only if a framework was found, not on error pages).
|
|
$( '#mw-javascripttest-summary' ).append( function () {
|
|
|
|
var $html = $( '<p><label for="useskin">'
|
|
+ mw.message( 'javascripttest-pagetext-skins' ).escaped()
|
|
+ ' '
|
|
+ '</label></p>' ),
|
|
select = '<select name="useskin" id="useskin">';
|
|
|
|
// Build <select> further
|
|
$.each( mw.config.get( 'wgAvailableSkins' ), function ( id ) {
|
|
select += '<option value="' + id + '"'
|
|
+ ( mw.config.get( 'skin' ) === id ? ' selected="selected"' : '' )
|
|
+ '>' + mw.message( 'skinname-' + id ).escaped() + '</option>';
|
|
} );
|
|
select += '</select>';
|
|
|
|
// Bind onchange event handler and append to form
|
|
$html.append(
|
|
$( select ).change( function () {
|
|
var url = new mw.Uri();
|
|
location.href = url.extend( { useskin: $( this ).val() } );
|
|
} )
|
|
);
|
|
|
|
return $html;
|
|
} );
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|