wdio-mediawiki: Move non-public methods to local scope
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 25 Jan 2019 19:05:57 +0000 (11:05 -0800)
committerJforrester <jforrester@wikimedia.org>
Sat, 9 Feb 2019 22:55:42 +0000 (22:55 +0000)
Change-Id: I56258290d7c731b913f4df21c0bf4adc7fe4c69f

tests/selenium/wdio-mediawiki/RunJobs.js

index 50ac601..9f36202 100644 (file)
@@ -2,6 +2,45 @@ const MWBot = require( 'mwbot' ),
        Page = require( './Page' ),
        FRONTPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless execution
 
+function getJobCount() {
+       let bot = new MWBot( {
+               apiUrl: `${browser.options.baseUrl}/api.php`
+       } );
+       return new Promise( ( resolve ) => {
+               return bot.request( {
+                       action: 'query',
+                       meta: 'siteinfo',
+                       siprop: 'statistics'
+               } ).then( ( response ) => {
+                       resolve( response.query.statistics.jobs );
+               } );
+       } );
+}
+
+function log( message ) {
+       process.stdout.write( `RunJobs ${message}\n` );
+}
+
+function runThroughFrontPageRequests( runCount = 1 ) {
+       let page = new Page();
+       log( `through requests to the front page (run ${runCount}).` );
+
+       page.openTitle( '' );
+
+       return getJobCount().then( ( jobCount ) => {
+               if ( jobCount === 0 ) {
+                       log( 'found no more queued jobs.' );
+                       return;
+               }
+               log( `detected ${jobCount} more queued job(s).` );
+               if ( runCount >= FRONTPAGE_REQUESTS_MAX_RUNS ) {
+                       log( 'stopping requests to the front page due to reached limit.' );
+                       return;
+               }
+               return runThroughFrontPageRequests( ++runCount );
+       } );
+}
+
 /**
  * Trigger the execution of jobs
  *
@@ -26,48 +65,9 @@ class RunJobs {
 
        static run() {
                browser.call( () => {
-                       return this.runThroughFrontPageRequests();
-               } );
-       }
-
-       static getJobCount() {
-               let bot = new MWBot( {
-                       apiUrl: `${browser.options.baseUrl}/api.php`
-               } );
-               return new Promise( ( resolve ) => {
-                       return bot.request( {
-                               action: 'query',
-                               meta: 'siteinfo',
-                               siprop: 'statistics'
-                       } ).then( ( response ) => {
-                               resolve( response.query.statistics.jobs );
-                       } );
-               } );
-       }
-
-       static runThroughFrontPageRequests( runCount = 1 ) {
-               let page = new Page();
-               this.log( `through requests to the front page (run ${runCount}).` );
-
-               page.openTitle( '' );
-
-               return this.getJobCount().then( ( jobCount ) => {
-                       if ( jobCount === 0 ) {
-                               this.log( 'found no more queued jobs.' );
-                               return;
-                       }
-                       this.log( `detected ${jobCount} more queued job(s).` );
-                       if ( runCount >= FRONTPAGE_REQUESTS_MAX_RUNS ) {
-                               this.log( 'stopping requests to the front page due to reached limit.' );
-                               return;
-                       }
-                       return this.runThroughFrontPageRequests( ++runCount );
+                       return runThroughFrontPageRequests();
                } );
        }
-
-       static log( message ) {
-               process.stdout.write( `RunJobs ${message}\n` );
-       }
 }
 
 module.exports = RunJobs;