Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(tsc): update types in emulation.js #5830

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions lighthouse-core/lib/emulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/
'use strict';

const Driver = require('../gather/driver'); // eslint-disable-line no-unused-vars
const mobile3G = require('../config/constants').throttling.mobile3G;
/** @typedef {import('../gather/driver.js')} Driver */

/**
* Nexus 5X metrics adapted from emulated_devices/module.json
Expand Down Expand Up @@ -51,15 +50,13 @@ const NO_THROTTLING_METRICS = {
const NO_CPU_THROTTLE_METRICS = {
rate: 1,
};
const CPU_THROTTLE_METRICS = {
rate: 4,
};

/**
* @param {Driver} driver
* @return {Promise<void>}
*/
function enableNexus5X(driver) {
return Promise.all([
async function enableNexus5X(driver) {
await Promise.all([
driver.sendCommand('Emulation.setDeviceMetricsOverride', NEXUS5X_EMULATION_METRICS),
// Network.enable must be called for UA overriding to work
driver.sendCommand('Network.enable'),
Expand All @@ -70,10 +67,10 @@ function enableNexus5X(driver) {

/**
* @param {Driver} driver
* @param {LH.ThrottlingSettings|undefined} throttlingSettings
* @param {Required<LH.ThrottlingSettings>} throttlingSettings
* @return {Promise<void>}
*/
function enableNetworkThrottling(driver, throttlingSettings = mobile3G) {
function enableNetworkThrottling(driver, throttlingSettings) {
/** @type {LH.Crdp.Network.EmulateNetworkConditionsRequest} */
const conditions = {
offline: false,
Expand Down Expand Up @@ -106,14 +103,11 @@ function goOffline(driver) {

/**
* @param {Driver} driver
* @param {LH.ThrottlingSettings|undefined} throttlingSettings
* @param {Required<LH.ThrottlingSettings>} throttlingSettings
* @return {Promise<void>}
*/
function enableCPUThrottling(driver, throttlingSettings) {
// TODO: cpuSlowdownMultiplier should be a required property by this point
const rate = throttlingSettings && throttlingSettings.cpuSlowdownMultiplier !== undefined
? throttlingSettings.cpuSlowdownMultiplier
: CPU_THROTTLE_METRICS.rate;
const rate = throttlingSettings.cpuSlowdownMultiplier;
return driver.sendCommand('Emulation.setCPUThrottlingRate', {rate});
}

Expand Down