jenkins-bot has submitted this change and it was merged.

Change subject: Simplify construction of qunit test module
......................................................................


Simplify construction of qunit test module

This is a first step towards cleaning up this auto-generation code.
We only need to register one module for tests.

Bug: T91659
Change-Id: I8a041384c173155fe0ae54efb3c524e25bd7a15f
---
M includes/MobileFrontend.hooks.php
M tests/qunit/mobile.issues/test_cleanuptemplates.js
M tests/qunit/mobile.toggle/test_toggle.js
R tests/qunit/tests.mobilefrontend/issues.hogan
R tests/qunit/tests.mobilefrontend/section.hogan
5 files changed, 26 insertions(+), 28 deletions(-)

Approvals:
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index ed8b861..811e8e2 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -257,51 +257,49 @@
        public static function onResourceLoaderTestModules( array &$testModules,
                ResourceLoader &$resourceLoader
        ) {
-               // FIXME: Global core variable
+               // FIXME: Global core variable don't use it.
                global $wgResourceModules;
-
-               $testModuleBoilerplate = array(
-                       'localBasePath' => dirname( __DIR__ ),
-                       'remoteExtPath' => 'MobileFrontend',
-                       'targets' => array( 'mobile' ),
-               );
-
-               // Expose templates module
-               $testModules['qunit']["tests.mobile.templates"] = 
$testModuleBoilerplate + array(
-                       'templates' => array(
-                               'section.hogan' => 
'tests/qunit/tests.mobile.templates/section.hogan',
-                               'issues.hogan' => 
'tests/qunit/tests.mobile.templates/issues.hogan',
-                       ),
-               );
+               $testFiles = array();
+               $dependencies = array();
+               $localBasePath = dirname( __DIR__ );
 
                // find test files for every RL module
                foreach ( $wgResourceModules as $key => $module ) {
+                       $hasTests = false;
                        if ( substr( $key, 0, 7 ) === 'mobile.' && isset( 
$module['scripts'] ) ) {
-                               $testFiles = array();
-                               $templates = array();
                                foreach ( $module['scripts'] as $script ) {
                                        $testFile = 'tests/' . dirname( $script 
) . '/test_' . basename( $script );
                                        // For resources folder
                                        $testFile = str_replace( 
'tests/resources/', 'tests/qunit/', $testFile );
                                        // if a test file exists for a given JS 
file, add it
-                                       if ( file_exists( 
$testModuleBoilerplate['localBasePath'] . '/' . $testFile ) ) {
+                                       if ( file_exists( $localBasePath . '/' 
. $testFile ) ) {
                                                $testFiles[] = $testFile;
+                                               $hasTests = true;
                                        }
                                }
 
                                // if test files exist for given module, create 
a corresponding test module
-                               if ( !empty( $testFiles ) ) {
-                                       $testModules['qunit']["$key.tests"] = 
$testModuleBoilerplate + array(
-                                               'dependencies' => array(
-                                                       $key,
-                                                       
'tests.mobile.templates',
-                                               ),
-                                               'scripts' => $testFiles,
-                                       );
+                               if ( $hasTests ) {
+                                       $dependencies[] = $key;
                                }
                        }
                }
 
+               $testModule = array(
+                       'dependencies' => $dependencies,
+                       'templates' => array(
+                               'section.hogan' => 
'tests/qunit/tests.mobilefrontend/section.hogan',
+                               'issues.hogan' => 
'tests/qunit/tests.mobilefrontend/issues.hogan',
+                       ),
+                       'localBasePath' => $localBasePath,
+                       'remoteExtPath' => 'MobileFrontend',
+                       'targets' => array( 'mobile', 'desktop' ),
+                       'scripts' => $testFiles,
+               );
+
+               // Expose templates module
+               $testModules['qunit']["tests.mobilefrontend"] = $testModule;
+
                return true;
        }
 
diff --git a/tests/qunit/mobile.issues/test_cleanuptemplates.js 
b/tests/qunit/mobile.issues/test_cleanuptemplates.js
index cf8e200..97eb42c 100644
--- a/tests/qunit/mobile.issues/test_cleanuptemplates.js
+++ b/tests/qunit/mobile.issues/test_cleanuptemplates.js
@@ -5,7 +5,7 @@
        QUnit.module( 'MobileFrontend issues', {
                setup: function () {
                        $( '<div id="mfe-test-issues">' +
-                       mw.template.get( 'tests.mobile.templates', 
'issues.hogan' ).text +
+                       mw.template.get( 'tests.mobilefrontend', 'issues.hogan' 
).text +
                        '</div>' ).appendTo( '#qunit-fixture' );
                },
                teardown: function () {
diff --git a/tests/qunit/mobile.toggle/test_toggle.js 
b/tests/qunit/mobile.toggle/test_toggle.js
index 8077eeb..3d253a0 100644
--- a/tests/qunit/mobile.toggle/test_toggle.js
+++ b/tests/qunit/mobile.toggle/test_toggle.js
@@ -1,6 +1,6 @@
 ( function ( M, $ ) {
 
-       var sectionHtml = mw.template.get( 'tests.mobile.templates', 
'section.hogan' ).render(),
+       var sectionHtml = mw.template.get( 'tests.mobilefrontend', 
'section.hogan' ).render(),
                settings = M.require( 'settings' ),
                browser = M.require( 'browser' ),
                page = { title: 'Toggle test' },
diff --git a/tests/qunit/tests.mobile.templates/issues.hogan 
b/tests/qunit/tests.mobilefrontend/issues.hogan
similarity index 100%
rename from tests/qunit/tests.mobile.templates/issues.hogan
rename to tests/qunit/tests.mobilefrontend/issues.hogan
diff --git a/tests/qunit/tests.mobile.templates/section.hogan 
b/tests/qunit/tests.mobilefrontend/section.hogan
similarity index 100%
rename from tests/qunit/tests.mobile.templates/section.hogan
rename to tests/qunit/tests.mobilefrontend/section.hogan

-- 
To view, visit https://gerrit.wikimedia.org/r/231630
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8a041384c173155fe0ae54efb3c524e25bd7a15f
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Bmansurov <bmansu...@wikimedia.org>
Gerrit-Reviewer: Phuedx <g...@samsmith.io>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to