X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialJavaScriptTest.php;h=f858f5c2cd3bbf707042763c5c43b61edeb2f0bb;hb=04d1aa3033f40a38d721f7f0e88b5bac440d2869;hp=dc6a61975066192df2bdf5e80b45de14d9e124c1;hpb=9c84cacd49f9d1fc19622959e2a64a30c4083ee8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialJavaScriptTest.php b/includes/specials/SpecialJavaScriptTest.php index dc6a619750..3e9676c64e 100644 --- a/includes/specials/SpecialJavaScriptTest.php +++ b/includes/specials/SpecialJavaScriptTest.php @@ -103,53 +103,62 @@ class SpecialJavaScriptTest extends SpecialPage { $query['only'] = 'scripts'; $startupContext = new ResourceLoaderContext( $rl, new FauxRequest( $query ) ); - $query['raw'] = true; - $modules = $rl->getTestModuleNames( 'qunit' ); // Disable autostart because we load modules asynchronously. By default, QUnit would start // at domready when there are no tests loaded and also fire 'QUnit.done' which then instructs - // Karma to end the run before the tests even started. + // Karma to exit the browser process before the tests even finished loading. $qunitConfig = 'QUnit.config.autostart = false;' . 'if (window.__karma__) {' // karma-qunit's use of autostart=false and QUnit.start conflicts with ours. - // Hack around this by replacing 'karma.loaded' with a no-op and call it ourselves later. - // See . + // Hack around this by replacing 'karma.loaded' with a no-op and perfom its duty of calling + // `__karma__.start()` ourselves. See . . 'window.__karma__.loaded = function () {};' . '}'; // The below is essentially a pure-javascript version of OutputPage::headElement(). - $startup = $rl->makeModuleResponse( $startupContext, [ + $code = $rl->makeModuleResponse( $startupContext, [ 'startup' => $rl->getModule( 'startup' ), ] ); - // Embed page-specific mw.config variables. - // The current Special page shouldn't be relevant to tests, but various modules (which - // are loaded before the test suites), reference mw.config while initialising. - $code = ResourceLoader::makeConfigSetScript( $out->getJSVars() ); - // Embed private modules as they're not allowed to be loaded dynamically - $code .= $rl->makeModuleResponse( $embedContext, [ - 'user.options' => $rl->getModule( 'user.options' ), - 'user.tokens' => $rl->getModule( 'user.tokens' ), - ] ); - // Catch exceptions (such as "dependency missing" or "unknown module") so that we - // always start QUnit. Re-throw so that they are caught and reported as global exceptions - // by QUnit and Karma. - $code .= '(function () {' - . 'var start = window.__karma__ ? window.__karma__.start : QUnit.start;' - . 'try {' - . 'mw.loader.using( ' . Xml::encodeJsVar( $modules ) . ' )' - . '.always( start )' - . '.fail( function ( e ) { throw e; } );' - . '} catch ( e ) { start(); throw e; }' - . '}());'; + $code .= <<getJSVars() ) + // Embed private modules as they're not allowed to be loaded dynamically + . $rl->makeModuleResponse( $embedContext, [ + 'user.options' => $rl->getModule( 'user.options' ), + 'user.tokens' => $rl->getModule( 'user.tokens' ), + ] ) + // Load all the test suites + . Xml::encodeJsCall( 'mw.loader.load', [ $modules ] ) + ); + $encModules = Xml::encodeJsVar( $modules ); + $code .= ResourceLoader::makeInlineCodeWithModule( 'mediawiki.base', <<makeResourceLoaderLink( 'jquery.qunit', ResourceLoaderModule::TYPE_SCRIPTS, - [ 'raw' => true, 'sync' => true ] + [ 'raw' => '1', 'sync' => '1' ] ); $head = implode( "\n", [ $styles, $scripts ] ); @@ -187,15 +196,6 @@ HTML; echo $html; } - /** - * Return an array of subpages that this special page will accept. - * - * @return string[] subpages - */ - public function getSubpagesForPrefixSearch() { - return self::$frameworks; - } - protected function getGroupName() { return 'other'; }