Skip to content

Commit

Permalink
Use prettier 2.0 and other new devdeps (#1652)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored Oct 7, 2021
1 parent 6f4c1f0 commit bcdaeae
Show file tree
Hide file tree
Showing 76 changed files with 729 additions and 874 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"prettier/prettier": [
"error",
{
"singleQuote": true
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid",
"embeddedLanguageFormatting": "off"
}
],
"no-extra-semi": "off",
Expand Down
2 changes: 1 addition & 1 deletion bin/browsertime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fs = require('fs');
const path = require('path');
const log = require('intel').getLogger('browsertime');
const engineUtils = require('../lib/support/engineUtils');
const AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
const delay = ms => new Promise(res => setTimeout(res, ms));

async function parseUserScripts(scripts) {
Expand Down
2 changes: 1 addition & 1 deletion lib/android/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Android {
const transfer = await this.client.pull(this.id, sourcePath);

return new Promise((resolve, reject) => {
transfer.on('end', function() {
transfer.on('end', function () {
resolve();
});
transfer.on('error', reject);
Expand Down
8 changes: 4 additions & 4 deletions lib/chrome/har.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const perflogParser = require('chrome-har');
const harBuilder = require('../support/har');
const { Type } = require('selenium-webdriver').logging;

module.exports = async function(
module.exports = async function (
runner,
result,
index,
Expand Down Expand Up @@ -38,9 +38,9 @@ module.exports = async function(
await cdpClient.setResponseBodies(har);
}

const versionInfo = (await cdpClient.send(
'Browser.getVersion'
)).product.split('/');
const versionInfo = (
await cdpClient.send('Browser.getVersion')
).product.split('/');
const info = {
name: versionInfo[0],
version: versionInfo[1]
Expand Down
2 changes: 1 addition & 1 deletion lib/chrome/longTaskMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const get = require('lodash.get');

module.exports = function(result, options) {
module.exports = function (result, options) {
let totalDurationFirstPaint = 0;
let totalDurationFirstContentFulPaint = 0;
let totalDurationAfterLoadEventEnd = 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/chrome/speedline.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function pad(n) {
* Use SpeedLine to analyse the Chrome trace log to get Visual Metrics.
* Not as good as using a video but maybe usable in some cases.
*/
module.exports = async function(trace, result, index) {
module.exports = async function (trace, result, index) {
try {
const navStart = trace.traceEvents.filter(
task =>
task.cat === 'blink.user_timing' && task.name === 'navigationStart'
);
navStart.sort(function(a, b) {
navStart.sort(function (a, b) {
return a.ts - b.ts;
});
log.debug('Get Speedline result from the trace');
Expand Down
2 changes: 1 addition & 1 deletion lib/chrome/webdriver/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let hasConfiguredChromeDriverService = false;
* @param builder
* @param {Object} options the options for a web driver.
*/
module.exports.configureBuilder = function(builder, baseDir, options) {
module.exports.configureBuilder = function (builder, baseDir, options) {
const chromeConfig = options.chrome || {};

if (!hasConfiguredChromeDriverService) {
Expand Down
2 changes: 1 addition & 1 deletion lib/chrome/webdriver/setupChromiumOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const getViewPort = require('../../support/getViewPort');
const util = require('../../support/util');
const log = require('intel').getLogger('browsertime.chrome');

module.exports = function(seleniumOptions, browserOptions, options, baseDir) {
module.exports = function (seleniumOptions, browserOptions, options, baseDir) {
// Fixing save password popup, only on Desktop
if (!options.android) {
seleniumOptions.setUserPreferences({
Expand Down
4 changes: 2 additions & 2 deletions lib/connectivity/trafficShapeParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const legacyProfiles = {
};

module.exports = {
parseTrafficShapeConfig: function(options) {
parseTrafficShapeConfig: function (options) {
if (options.connectivity && options.connectivity.profile === 'custom') {
return {
down: options.connectivity.down,
Expand Down Expand Up @@ -133,7 +133,7 @@ module.exports = {
return null;
}
},
getProfiles: function() {
getProfiles: function () {
return newProfiles;
}
};
6 changes: 3 additions & 3 deletions lib/connectivity/tsProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TS_PROXY_SCRIPT_PATH = path.join(
);

function getStartupCriteriaListener(resolve, reject) {
return function(data) {
return function (data) {
const logLine = data.toString();
if (logLine.startsWith('Started Socks5 proxy server on')) {
log.debug('Started TSproxy');
Expand Down Expand Up @@ -65,12 +65,12 @@ class TSProxy {
const tsProxyProcess = this.tsProxyProcess;

if (this.logVerbose) {
tsProxyProcess.stderr.on('data', function(data) {
tsProxyProcess.stderr.on('data', function (data) {
log.verbose(data.toString().trim());
});
}

return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
tsProxyProcess.stdout.on(
'data',
getStartupCriteriaListener(resolve, reject)
Expand Down
10 changes: 4 additions & 6 deletions lib/core/engine/command/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,12 @@ class Measure {
// we also need to add that to the meta data so that the correct folder is created
if (this.result[this.numberOfMeasuredPages].alias) {
if (this.options.urlMetaData) {
this.options.urlMetaData[url] = this.result[
this.numberOfMeasuredPages
].alias;
this.options.urlMetaData[url] =
this.result[this.numberOfMeasuredPages].alias;
} else {
this.options.urlMetaData = {};
this.options.urlMetaData[url] = this.result[
this.numberOfMeasuredPages
].alias;
this.options.urlMetaData[url] =
this.result[this.numberOfMeasuredPages].alias;
}
}

Expand Down
20 changes: 4 additions & 16 deletions lib/core/engine/command/mouse/clickAndHold.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class ClickAndHold {
async byXpath(xpath) {
try {
const element = await this.driver.findElement(webdriver.By.xpath(xpath));
return this.actions
.move({ origin: element })
.press()
.perform();
return this.actions.move({ origin: element }).press().perform();
} catch (e) {
log.error('Could not click and hold on element with xpath %s', xpath);
log.verbose(e);
Expand All @@ -38,10 +35,7 @@ class ClickAndHold {
async bySelector(selector) {
try {
const element = await this.driver.findElement(webdriver.By.css(selector));
return this.actions
.move({ origin: element })
.press()
.perform();
return this.actions.move({ origin: element }).press().perform();
} catch (e) {
log.error(
'Could not click and hold on element with selector %s',
Expand Down Expand Up @@ -103,10 +97,7 @@ class ClickAndHold {
async releaseAtXpath(xpath) {
try {
const element = await this.driver.findElement(webdriver.By.xpath(xpath));
return this.actions
.move({ origin: element })
.release()
.perform();
return this.actions.move({ origin: element }).release().perform();
} catch (e) {
log.error('Could not release on xpath %s', xpath);
log.verbose(e);
Expand All @@ -123,10 +114,7 @@ class ClickAndHold {
async releaseAtSelector(selector) {
try {
const element = await this.driver.findElement(webdriver.By.css(selector));
return this.actions
.move({ origin: element })
.release()
.perform();
return this.actions.move({ origin: element }).release().perform();
} catch (e) {
log.error('Could not release on selector %s', selector);
log.verbose(e);
Expand Down
10 changes: 2 additions & 8 deletions lib/core/engine/command/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ class Switch {
*/
async toNewTab(url) {
try {
await this.browser
.getDriver()
.switchTo()
.newWindow('tab');
await this.browser.getDriver().switchTo().newWindow('tab');
if (url) {
await this.navigate(url);
await this.browser.extraWait(this.pageCompleteCheck);
Expand All @@ -80,10 +77,7 @@ class Switch {
*/
async toNewWindow(url) {
try {
await this.browser
.getDriver()
.switchTo()
.newWindow('window');
await this.browser.getDriver().switchTo().newWindow('window');
if (url) {
await this.navigate(url);
await this.browser.extraWait(this.pageCompleteCheck);
Expand Down
9 changes: 4 additions & 5 deletions lib/core/engine/iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,10 @@ class Iteration {
'PerceptualSpeedIndexProgress'
]) {
if (videoMetrics.visualMetrics[progress]) {
videoMetrics.visualMetrics[
progress
] = util.jsonifyVisualProgress(
videoMetrics.visualMetrics[progress]
);
videoMetrics.visualMetrics[progress] =
util.jsonifyVisualProgress(
videoMetrics.visualMetrics[progress]
);
}
}
result[i].videoRecordingStart = videoMetrics.videoRecordingStart;
Expand Down
4 changes: 2 additions & 2 deletions lib/core/engine/run.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = function(urlOrFunctions) {
return async function(context, commands) {
module.exports = function (urlOrFunctions) {
return async function (context, commands) {
for (let urlOrFunction of urlOrFunctions) {
if (typeof urlOrFunction === 'function') {
await urlOrFunction(context, commands);
Expand Down
45 changes: 23 additions & 22 deletions lib/core/seleniumRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ class SeleniumRunner {
this.driver = await timeout(
builder.createWebDriver(this.baseDir, this.options),
this.options.timeouts.browserStart,
`Failed to start ${this.options.browser} in ${this.options.timeouts
.browserStart / 1000} seconds.`
`Failed to start ${this.options.browser} in ${
this.options.timeouts.browserStart / 1000
} seconds.`
);
break;
} catch (e) {
Expand All @@ -85,9 +86,9 @@ class SeleniumRunner {
throw e;
} else {
log.info(
`${this.options.browser} failed to start, trying ${tries -
i -
1} more time(s): ${e.message}`
`${this.options.browser} failed to start, trying ${
tries - i - 1
} more time(s): ${e.message}`
);
}
}
Expand Down Expand Up @@ -167,11 +168,13 @@ class SeleniumRunner {
try {
const pageCompleteCheckCondition = new Condition(
'for page complete check script to return true',
function(d) {
return d.executeScript(pageCompleteCheck, waitTime).then(function(t) {
log.verbose('PageCompleteCheck returned %s', t);
return t === true;
});
function (d) {
return d
.executeScript(pageCompleteCheck, waitTime)
.then(function (t) {
log.verbose('PageCompleteCheck returned %s', t);
return t === true;
});
}
);
log.debug(
Expand Down Expand Up @@ -297,9 +300,9 @@ class SeleniumRunner {
log.info(
`URL ${url} failed to load, the ${
this.options.browser
} are still on ${startURI} , trying ${tries -
i -
1} more time(s) but first wait for ${waitTime} ms.`
} are still on ${startURI} , trying ${
tries - i - 1
} more time(s) but first wait for ${waitTime} ms.`
);

if (i === tries - 1) {
Expand Down Expand Up @@ -476,13 +479,11 @@ class SeleniumRunner {
*/
async getLogs(logType) {
return timeout(
this.driver
.manage()
.logs()
.get(logType),
this.driver.manage().logs().get(logType),
this.options.timeouts.logs,
`Extracting logs from ${this.options.browser} took more than ${this
.options.timeouts.logs / 1000} seconds.`
`Extracting logs from ${this.options.browser} took more than ${
this.options.timeouts.logs / 1000
} seconds.`
);
}

Expand Down Expand Up @@ -626,9 +627,9 @@ class SeleniumRunner {
if (!script) {
let func = category[scriptName].function;
if (!func) {
throw 'Function and script cannot both be null in ' +
scriptName +
'.';
throw (
'Function and script cannot both be null in ' + scriptName + '.'
);
}
// We wrap the source code of the function in parenthesis
// "(...)" to contain it in a separate scope. We add a
Expand Down
2 changes: 1 addition & 1 deletion lib/core/webdriver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const safari = require('../../safari/webdriver/builder');
* @returns {!Promise<webdriver.WebDriver>} a promise that resolves to the webdriver,
* or rejects if the current configuration is invalid.
*/
module.exports.createWebDriver = async function(baseDir, options) {
module.exports.createWebDriver = async function (baseDir, options) {
const browser = options.browser || 'chrome';
const seleniumUrl = options.selenium ? options.selenium.url : undefined;
const capabilities = options.selenium
Expand Down
2 changes: 1 addition & 1 deletion lib/edge/webdriver/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const isEmpty = require('lodash.isempty');
const webdriver = require('selenium-webdriver');
const setupChromiumOptions = require('../../chrome/webdriver/setupChromiumOptions');

module.exports.configureBuilder = function(builder, baseDir, options) {
module.exports.configureBuilder = function (builder, baseDir, options) {
const edgeConfig = options.edge || {};
const chromeConfig = options.chrome || {};

Expand Down
2 changes: 1 addition & 1 deletion lib/extensionserver/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function generateURL(port, testUrl, options) {
});
}

module.exports = async function(url, browser, port, options) {
module.exports = async function (url, browser, port, options) {
const configUrl = generateURL(port, url, options);
log.debug('Configuring browser plugin via %s', configUrl);
await browser.loadAndWait(configUrl);
Expand Down
5 changes: 2 additions & 3 deletions lib/firefox/geckoProfiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class GeckoProfiler {
const runner = this.runner;
const firefoxConfig = this.firefoxConfig;
const options = this.options;
const chosenFeatures = firefoxConfig.geckoProfilerParams.features.split(
','
);
const chosenFeatures =
firefoxConfig.geckoProfilerParams.features.split(',');
const featureString = '["' + chosenFeatures.join('","') + '"]';

const chosenThreads = firefoxConfig.geckoProfilerParams.threads.split(',');
Expand Down
2 changes: 1 addition & 1 deletion lib/firefox/getHAR.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const log = require('intel').getLogger('browsertime.firefox');

// Get the HAR from Firefox
// Using https://github.com/firefox-devtools/har-export-trigger
module.exports = async function(runner, includeResponseBodies) {
module.exports = async function (runner, includeResponseBodies) {
const script = `
const callback = arguments[arguments.length - 1];
async function triggerExport() {
Expand Down
Loading

0 comments on commit bcdaeae

Please sign in to comment.