selenium: Replace ES5 one-var assignments with const/let per line
[lhc/web/wiklou.git] / tests / selenium / wdio-mediawiki / RunJobs.js
index 50ac601..daa7fbd 100644 (file)
@@ -1,6 +1,43 @@
-const MWBot = require( 'mwbot' ),
-       Page = require( './Page' ),
-       FRONTPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless execution
+const MWBot = require( 'mwbot' );
+const Page = require( './Page' );
+const MAINPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless execution
+
+function getJobCount() {
+       const bot = new MWBot( {
+               apiUrl: `${browser.config.baseUrl}/api.php`
+       } );
+       return bot.request( {
+               action: 'query',
+               meta: 'siteinfo',
+               siprop: 'statistics'
+       } ).then( ( response ) => {
+               return response.query.statistics.jobs;
+       } );
+}
+
+function log( message ) {
+       process.stdout.write( `RunJobs ${message}\n` );
+}
+
+function runThroughMainPageRequests( runCount = 1 ) {
+       const page = new Page();
+       log( `through requests to the main 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 >= MAINPAGE_REQUESTS_MAX_RUNS ) {
+                       log( 'stopping requests to the main page due to reached limit.' );
+                       return;
+               }
+               return runThroughMainPageRequests( ++runCount );
+       } );
+}
 
 /**
  * Trigger the execution of jobs
@@ -26,48 +63,9 @@ class RunJobs {
 
        static run() {
                browser.call( () => {
-                       return this.runThroughFrontPageRequests();
+                       return runThroughMainPageRequests();
                } );
        }
-
-       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 );
-               } );
-       }
-
-       static log( message ) {
-               process.stdout.write( `RunJobs ${message}\n` );
-       }
 }
 
 module.exports = RunJobs;