From: Timo Tijhof Date: Fri, 25 Jan 2019 19:05:57 +0000 (-0800) Subject: wdio-mediawiki: Move non-public methods to local scope X-Git-Tag: 1.34.0-rc.0~2869^2~1 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=a1e51bf94325130fa3d54d65c071d3ab57a4ab79 wdio-mediawiki: Move non-public methods to local scope Change-Id: I56258290d7c731b913f4df21c0bf4adc7fe4c69f --- diff --git a/tests/selenium/wdio-mediawiki/RunJobs.js b/tests/selenium/wdio-mediawiki/RunJobs.js index 50ac601c5e..9f36202bf2 100644 --- a/tests/selenium/wdio-mediawiki/RunJobs.js +++ b/tests/selenium/wdio-mediawiki/RunJobs.js @@ -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;