Manual:Hooks/ResourceLoaderTestModules
From Linux Web Expert
File:OOjs UI icon alert-destructive.svg | <translate> This feature was removed from MediaWiki core in version <tvar name=ver>1.40.0</tvar> (after being deprecated in <tvar name=4>1.33.0</tvar>).</translate> <translate> Please see <tvar name=page>QUnitTestModule</tvar> for an alternative way to use this feature.</translate> |
ResourceLoaderTestModules | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar (r107919, codereview)</tvar></translate> <translate> Removed in <tvar name=1><translate> version <tvar (Gerrit change 861504)</tvar></translate> Add new javascript test suites. This is called after the addition of MediaWiki core test suites. | |
<translate> Define function:</translate> | public static function onResourceLoaderTestModules( array &$modules, ResourceLoader $resourceLoader ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"ResourceLoaderTestModules": "MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderTestModules"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> resourceloader/ResourceLoader.php <translate> Function(s):</translate> registerTestModules |
<translate> Interface:</translate> | ResourceLoaderTestModulesHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ResourceLoaderTestModules extensions</tvar>.</translate>
Details
&$modules
: array of javascript testing modules, keyed by framework (e.g.'qunit'
).$resourceLoader
: ResourceLoader object
Usage
This hook is run on wikis that have $wgEnableJavaScriptTest
set to true
.
Don't forget to add the module that is being tested to the dependencies!
$modules['qunit']['ext.example.test'] = [
'scripts' => [
'tests/ext.example.foo.test.js',
'tests/ext.example.bar.test.js',
],
'dependencies' => [
'ext.example.foo',
'ext.example.bar',
],
'localBasePath' => __DIR__,
'remoteExtPath' => 'Example',
];
The array syntax is equal to that of ResourceLoaderRegisterModules and $wgResourceModules
. This means idioms such as remoteExtPath
and remoteSkinPath
work here too.
See revision 109127 for an example of adding test support to an extension.