Ori.livneh has submitted this change and it was merged. Change subject: asset-check: Minor code clean up ......................................................................
asset-check: Minor code clean up * Whitelist non-standard global 'phantomjs' to satisfy jshint. * Move regex execution in parseArgument() to after the early return where it wasn't being used. * Whitespace in object literlas and function call line continuation. * Fix masked error where regex result array was casted to a string inside bracket access. * Most inline commments didn't end in a full stop, make them consistent by removing it from the two comments that did. Change-Id: Ica8dbc689cf5c6da4c18a29daeb386d638fccc0b --- M modules/webperf/files/asset-check.js 1 file changed, 20 insertions(+), 14 deletions(-) Approvals: Ori.livneh: Verified; Looks good to me, approved diff --git a/modules/webperf/files/asset-check.js b/modules/webperf/files/asset-check.js index e8c245d..865d226 100644 --- a/modules/webperf/files/asset-check.js +++ b/modules/webperf/files/asset-check.js @@ -16,17 +16,20 @@ * Copyright (C) 2013, Ori Livneh <[email protected]> * Licensed under the terms of the GPL, version 2 or later. */ +/*global phantom */ var system = require( 'system' ), webpage = require( 'webpage' ), - options = { timeout: 30, ua: null }; + options = { + timeout: 30, + ua: null, + }; function parseArgument( arg ) { - var match = /^--([^=]+)=(.*)/.exec( arg ); - if ( arg === '-h' || arg === '--help' ) { usage(); } + var match = /^--([^=]+)=(.*)/.exec( arg ); if ( match ) { options[ match[1] ] = match[2]; } else { @@ -36,7 +39,8 @@ function usage() { console.error( 'Usage: phantomjs ' + system.args[ 0 ] + - ' URL [--timeout=N] [--ua=USER_AGENT_STRING]' ); + ' URL [--timeout=N] [--ua=USER_AGENT_STRING]' + ); phantom.exit( 1 ); } @@ -48,12 +52,12 @@ function checkAssets( url ) { var payload = { - javascript : { requests : 0, bytes : 0 }, - html : { requests : 0, bytes : 0 }, - css : { requests : 0, bytes : 0, rules : 0 }, - image : { requests : 0, bytes : 0 }, - other : { requests : 0, bytes : 0 }, - cookies : { set: 0 }, + javascript: { requests: 0, bytes: 0 }, + html: { requests: 0, bytes: 0 }, + css: { requests: 0, bytes: 0, rules: 0 }, + image: { requests: 0, bytes: 0 }, + other: { requests: 0, bytes: 0 }, + cookies: { set: 0 }, }; var page = webpage.create(); @@ -64,8 +68,10 @@ // Analyze incoming resource page.onResourceReceived = function ( res ) { - var type = /image|javascript|css|html/i.exec( res.contentType ) || 'other', - resource = payload[type]; + var match = /javascript|html|css|image/i.exec( res.contentType ) || [ 'other' ], + type = match[0], + resource = payload[ type ]; + if ( res.bodySize && !/^data:/.test( res.url ) ) { resource.requests++; resource.bytes += res.bodySize; @@ -80,7 +86,7 @@ phantom.exit( 0 ); }; - // Abort if 30 seconds elapsed and the page hasn't finished loading. + // Abort if 30 seconds elapsed and the page hasn't finished loading setTimeout( function () { console.error( 'Timed out after ' + options.timeout + ' seconds.' ); phantom.exit( 1 ); @@ -88,7 +94,7 @@ page.open( url ); - // Page is locked to the specified URL. + // Page is locked to the specified URL page.navigationLocked = true; } -- To view, visit https://gerrit.wikimedia.org/r/137240 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ica8dbc689cf5c6da4c18a29daeb386d638fccc0b Gerrit-PatchSet: 3 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Krinkle <[email protected]> Gerrit-Reviewer: Ori.livneh <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
