41 parent::__construct(
'JavaScriptTest' );
47 if ( $par ===
'qunit/export' ) {
50 } elseif ( $par ===
null || $par ===
'' || $par ===
'qunit' || $par ===
'qunit/plain' ) {
55 wfHttpError( 404,
'Unknown action',
"Unknown action \"$par\"." );
64 private function exportJS() {
67 $rl = $out->getResourceLoader();
71 $out->setPreventClickjacking(
false );
76 'debug' => $req->getRawVal(
'debug' ),
80 $query[
'only'] =
'scripts';
83 $modules = $rl->getTestSuiteModuleNames();
84 $component = $req->getRawVal(
'component' );
86 $module =
'test.' . $component;
87 if ( !in_array(
'test.' . $component, $modules ) ) {
90 'Unknown test module',
91 "'$module' is not a defined test module. "
92 .
'Register one via the QUnitTestModules attribute in extension.json.'
96 $modules = [
'test.' . $component ];
101 $config =
new MultiConfig( [
107 $startupModule = $rl->getModule(
'startup' );
108 $startupModule->setConfig( $config );
109 $code = $rl->makeModuleResponse( $startupContext, [
'startup' => $startupModule ] );
111 $code .= ResourceLoader::makeLoaderConditionalScript(
125 ResourceLoader::makeConfigSetScript( [
127 'wgPageName' =>
'Special:Badtitle/JavaScriptTest',
129 'wgRelevantPageName' =>
'Special:Badtitle/JavaScriptTest',
132 . $rl->makeModuleResponse( $embedContext, [
133 'user.options' => $rl->getModule(
'user.options' ),
136 . Html::encodeJsCall(
'mw.loader.load', [ $modules ] )
138 $encModules = Html::encodeJsVar( $modules );
139 $code .= ResourceLoader::makeInlineCodeWithModule(
'mediawiki.base', <<<JAVASCRIPT
142 var promises = $encModules.map(
function( module ) {
143 return mw.loader.using( module ).promise();
145 Promise.allSettled( promises ).then( QUnit.start );
149 header(
'Content-Type: text/javascript; charset=utf-8' );
150 header(
'Cache-Control: private, no-cache, must-revalidate' );
154 private function renderPage() {
156 $headHtml = implode(
"\n", [
157 Html::linkedStyle(
"$basePath/resources/lib/qunitjs/qunit.css" ),
158 Html::linkedStyle(
"$basePath/resources/src/qunitjs/qunit-local.css" ),
161 $introHtml = $this->
msg(
'javascripttest-qunit-intro' )
162 ->params(
'https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing' )
165 $scriptUrl = $this->
getPageTitle(
'qunit/export' )->getFullURL( [
166 'debug' => (
string)ResourceLoader::inDebugMode(),
168 $script = implode(
"\n", [
169 Html::linkedScript(
"$basePath/resources/lib/qunitjs/qunit.js" ),
170 Html::inlineScript(
'QUnit.config.autostart = false;' ),
171 Html::linkedScript( $scriptUrl ),
174 header(
'Content-Type: text/html; charset=utf-8' );
180<div
id=
"qunit"></div>
181<div
id=
"qunit-fixture"></div>
192class_alias( SpecialJavaScriptTest::class,
'SpecialJavaScriptTest' );
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
A class containing constants representing the names of configuration variables.
const ResourceBasePath
Name constant for the ResourceBasePath setting, for use with Config::get()
const ResourceLoaderStorageEnabled
Name constant for the ResourceLoaderStorageEnabled setting, for use with Config::get()
Context object that contains information about the state of a specific ResourceLoader web request.
Parent class for all special pages.
getPageTitle( $subpage=false)
Get a self-referential title object.
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.