40 parent::__construct(
'JavaScriptTest' );
46 if ( $par ===
'qunit/export' ) {
49 } elseif ( $par ===
null || $par ===
'' || $par ===
'qunit' || $par ===
'qunit/plain' ) {
54 wfHttpError( 404,
'Unknown action',
"Unknown action \"$par\"." );
61 private function getModulesForComponentOrThrow( ?
string $component ): array {
63 $rl = $out->getResourceLoader();
66 $modules = $rl->getTestSuiteModuleNames();
67 if ( $component !==
null ) {
68 $module =
'test.' . $component;
69 if ( !in_array(
'test.' . $component, $modules ) ) {
72 "No test module found for the '$component' component.\n"
73 .
"Make sure the extension is enabled via wfLoadExtension(),\n"
74 .
"and register a test module via the QUnitTestModules attribute in extension.json.",
75 'Unknown test module',
78 $modules = [
'test.' . $component ];
89 private function exportJS() {
90 $out = $this->getOutput();
92 $rl = $out->getResourceLoader();
96 $out->getMetadata()->setPreventClickjacking(
false );
100 'skin' =>
'fallback',
101 'debug' => $req->getRawVal(
'debug' ),
104 $embedContext =
new RL\Context( $rl,
new FauxRequest( $query ) );
105 $query[
'only'] =
'scripts';
106 $startupContext =
new RL\Context( $rl,
new FauxRequest( $query ) );
108 $component = $req->getRawVal(
'component' );
109 $modules = $this->getModulesForComponentOrThrow( $component );
113 $config =
new MultiConfig( [
119 $startupModule = $rl->getModule(
'startup' );
120 $startupModule->setConfig( $config );
121 $code = $rl->makeModuleResponse( $startupContext, [
'startup' => $startupModule ] );
123 $code .= ResourceLoader::makeLoaderConditionalScript(
137 ResourceLoader::makeConfigSetScript( [
139 'wgPageName' =>
'Special:Badtitle/JavaScriptTest',
141 'wgRelevantPageName' =>
'Special:Badtitle/JavaScriptTest',
144 . $rl->makeModuleResponse( $embedContext, [
145 'user.options' => $rl->getModule(
'user.options' ),
148 . Html::encodeJsCall(
'mw.loader.load', [ $modules ] )
150 $encModules = Html::encodeJsVar( $modules );
151 $code .= ResourceLoader::makeInlineCodeWithModule(
'mediawiki.base', <<<JAVASCRIPT
154 var promises = $encModules.map(
function( module ) {
155 return mw.loader.using( module ).promise();
157 Promise.allSettled( promises ).then( QUnit.start );
161 header(
'Content-Type: text/javascript; charset=utf-8' );
162 header(
'Cache-Control: private, no-cache, must-revalidate' );
166 private function renderPage() {
168 $component = $req->getRawVal(
'component' );
170 $this->getModulesForComponentOrThrow( $component );
173 $headHtml = implode(
"\n", [
174 Html::linkedStyle(
"$basePath/resources/lib/qunitjs/qunit.css" ),
175 Html::linkedStyle(
"$basePath/resources/src/qunitjs/qunit-local.css" ),
178 $scriptUrl = $this->getPageTitle(
'qunit/export' )->getFullURL( [
179 'debug' => (
string)ResourceLoader::inDebugMode(),
180 'component' => $component,
182 $script = implode(
"\n", [
183 Html::linkedScript(
"$basePath/resources/lib/qunitjs/qunit.js" ),
184 Html::inlineScript(
'QUnit.config.autostart = false;' ),
185 Html::linkedScript( $scriptUrl ),
188 header(
'Content-Type: text/html; charset=utf-8' );
193<div
id=
"qunit"></div>
194<div
id=
"qunit-fixture"></div>