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.'
101 $config =
new MultiConfig( [
109 $qunitConfig =
'QUnit.config.autostart = false;'
110 .
'if (window.__karma__) {'
114 .
'window.__karma__.loaded = function () {};'
118 $startupModule = $rl->getModule(
'startup' );
119 $startupModule->setConfig( $config );
120 $code = $rl->makeModuleResponse( $startupContext, [
'startup' => $startupModule ] );
122 $code .= ResourceLoader::makeLoaderConditionalScript(
136 ResourceLoader::makeConfigSetScript( [
138 'wgPageName' =>
'Special:Badtitle/JavaScriptTest',
140 'wgRelevantPageName' =>
'Special:Badtitle/JavaScriptTest',
143 . $rl->makeModuleResponse( $embedContext, [
144 'user.options' => $rl->getModule(
'user.options' ),
147 . Html::encodeJsCall(
'mw.loader.load', [
$modules ] )
149 $encModules = Html::encodeJsVar(
$modules );
150 $code .= ResourceLoader::makeInlineCodeWithModule(
'mediawiki.base', <<<JAVASCRIPT
151 var start = window.__karma__ ? window.__karma__.start : QUnit.start;
154 var promises = $encModules.map(
function( module ) {
155 return mw.loader.using( module ).promise();
157 Promise.allSettled( promises ).then( start );
158 mw.trackSubscribe(
'resourceloader.exception',
function ( topic, err ) {
161 setTimeout(
function () {
168 header(
'Content-Type: text/javascript; charset=utf-8' );
169 header(
'Cache-Control: private, no-cache, must-revalidate' );
174 private function renderPage() {
176 $headHtml = implode(
"\n", [
177 Html::linkedScript(
"$basePath/resources/lib/qunitjs/qunit.js" ),
178 Html::linkedStyle(
"$basePath/resources/lib/qunitjs/qunit.css" ),
179 Html::linkedStyle(
"$basePath/resources/src/qunitjs/qunit-local.css" ),
182 $introHtml = $this->
msg(
'javascripttest-qunit-intro' )
183 ->params(
'https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing' )
186 $scriptUrl = $this->
getPageTitle(
'qunit/export' )->getFullURL( [
187 'debug' => (
string)ResourceLoader::inDebugMode(),
189 $script = Html::linkedScript( $scriptUrl );
191 header(
'Content-Type: text/html; charset=utf-8' );
197<div
id=
"qunit"></div>
198<div
id=
"qunit-fixture"></div>
211class_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.