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): add type checking to gather-runner #4944

Merged
merged 4 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions lighthouse-cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function isDev() {
// Tell user if there's a newer version of LH.
updateNotifier({pkg}).notify();

const /** @type {!LH.Flags} */ cliFlags = getFlags();
const /** @type {LH.Flags} */ cliFlags = getFlags();

// Process terminating command
if (cliFlags.listAllAudits) {
Expand All @@ -48,16 +48,16 @@ if (cliFlags.listTraceCategories) {
/** @type {string} */
const url = cliFlags._[0];

/** @type {!LH.Config|undefined} */
/** @type {LH.Config.Json|undefined} */
let config;
if (cliFlags.configPath) {
// Resolve the config file path relative to where cli was called.
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath);
config = /** @type {!LH.Config} */ (require(cliFlags.configPath));
config = /** @type {LH.Config.Json} */ (require(cliFlags.configPath));
} else if (cliFlags.perf) {
config = /** @type {!LH.Config} */ (perfOnlyConfig);
config = perfOnlyConfig;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these are now js files, typescript now imports them and checks that they're compatible with being assigned to LH.Config.Json|undefined here :)

} else if (cliFlags.mixedContent) {
config = /** @type {!LH.Config} */ (mixedContentConfig);
config = mixedContentConfig;
// The mixed-content audits require headless Chrome (https://crbug.com/764505).
cliFlags.chromeFlags = `${cliFlags.chromeFlags} --headless`;
}
Expand All @@ -84,7 +84,7 @@ if (cliFlags.extraHeaders) {
}

/**
* @return {!Promise<(void|!LH.Results)>}
* @return {Promise<LH.Results|void>}
*/
function run() {
return Promise.resolve()
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ function saveResults(results, artifacts, flags) {

/**
* @param {string} url
* @param {!LH.Flags} flags
* @param {!LH.Config|undefined} config
* @param {LH.Flags} flags
* @param {LH.Config.Json|undefined} config
* @return {Promise<LH.Results|void>}
*/
function runLighthouse(url, flags, config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ConsistentlyInteractive extends MetricArtifact {
/**
* @param {{trace: Object, devtoolsLog: Object}} data
* @param {Object} artifacts
* @return {Promise<LH.Gatherer.Artifact.LanternMetric>}
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
async compute_(data, artifacts) {
const fmpResult = await artifacts.requestLanternFirstMeaningfulPaint(data, artifacts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FirstContentfulPaint extends MetricArtifact {

/**
* @param {!Node} dependencyGraph
* @param {LH.Gatherer.Artifact.TraceOfTab} traceOfTab
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {!Node}
*/
getOptimisticGraph(dependencyGraph, traceOfTab) {
Expand All @@ -54,7 +54,7 @@ class FirstContentfulPaint extends MetricArtifact {

/**
* @param {!Node} dependencyGraph
* @param {LH.Gatherer.Artifact.TraceOfTab} traceOfTab
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {!Node}
*/
getPessimisticGraph(dependencyGraph, traceOfTab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FirstMeaningfulPaint extends MetricArtifact {

/**
* @param {!Node} dependencyGraph
* @param {LH.Gatherer.Artifact.TraceOfTab} traceOfTab
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {!Node}
*/
getOptimisticGraph(dependencyGraph, traceOfTab) {
Expand All @@ -54,7 +54,7 @@ class FirstMeaningfulPaint extends MetricArtifact {

/**
* @param {!Node} dependencyGraph
* @param {LH.Gatherer.Artifact.TraceOfTab} traceOfTab
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {!Node}
*/
getPessimisticGraph(dependencyGraph, traceOfTab) {
Expand All @@ -80,7 +80,7 @@ class FirstMeaningfulPaint extends MetricArtifact {
/**
* @param {{trace: Object, devtoolsLog: Object}} data
* @param {Object} artifacts
* @return {Promise<LH.Gatherer.Artifact.LanternMetric>}
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
async compute_(data, artifacts) {
const fcpResult = await artifacts.requestLanternFirstContentfulPaint(data, artifacts);
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-core/gather/computed/metrics/lantern-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LanternMetricArtifact extends ComputedArtifact {

/**
* @param {!Node} dependencyGraph
* @param {LH.Gatherer.Artifact.TraceOfTab} traceOfTab
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {!Node}
*/
getOptimisticGraph(dependencyGraph, traceOfTab) { // eslint-disable-line no-unused-vars
Expand All @@ -49,7 +49,7 @@ class LanternMetricArtifact extends ComputedArtifact {

/**
* @param {!Node} dependencyGraph
* @param {LH.Gatherer.Artifact.TraceOfTab} traceOfTab
* @param {LH.Artifacts.TraceOfTab} traceOfTab
* @return {!Node}
*/
getPessimisticGraph(dependencyGraph, traceOfTab) { // eslint-disable-line no-unused-vars
Expand All @@ -69,7 +69,7 @@ class LanternMetricArtifact extends ComputedArtifact {
* @param {{trace: Object, devtoolsLog: Object}} data
* @param {Object} artifacts
* @param {any=} extras
* @return {Promise<LH.Gatherer.Artifact.LanternMetric>}
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
async computeMetricWithGraphs(data, artifacts, extras) {
const {trace, devtoolsLog} = data;
Expand Down Expand Up @@ -112,7 +112,7 @@ class LanternMetricArtifact extends ComputedArtifact {
/**
* @param {{trace: Object, devtoolsLog: Object}} data
* @param {Object} artifacts
* @return {Promise<LH.Gatherer.Artifact.LanternMetric>}
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
compute_(data, artifacts) {
return this.computeMetricWithGraphs(data, artifacts);
Expand Down
2 changes: 0 additions & 2 deletions lighthouse-core/gather/connections/cri.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class CriConnection extends Connection {

// After aborting, we expect an ECONNRESET error. Ignore.
request.on('error', err => {
// @ts-ignore `code` property extension to Error by Node.
if (err.code !== 'ECONNRESET') {
throw err;
}
Expand All @@ -122,7 +121,6 @@ class CriConnection extends Connection {
// TODO: Replace this with an LHError on next major version bump
// Reject on error with code specifically indicating timeout in connection setup.
const err = new Error('Timeout waiting for initial Debugger Protocol connection.');
// @ts-ignore fixed by above TODO
err.code = 'CRI_TIMEOUT';
log.error('CriConnection', err.message);
reject(err);
Expand Down
25 changes: 12 additions & 13 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ class Driver {
*/
async gotoURL(url, options = {}) {
const waitForLoad = options.waitForLoad || false;
const passContext = options.passContext || {};
const passContext = /** @type {Partial<LH.Gatherer.PassContext>} */ (options.passContext || {});
const disableJS = passContext.disableJavaScript || false;

await this._beginNetworkStatusMonitoring(url);
Expand All @@ -678,7 +678,7 @@ class Driver {
this.sendCommand('Page.navigate', {url});

if (waitForLoad) {
const passConfig = passContext.passConfig || {};
const passConfig = /** @type {Partial<LH.Config.Pass>} */ (passContext.passConfig || {});
let {pauseAfterLoadMs, networkQuietThresholdMs, cpuQuietThresholdMs} = passConfig;
let maxWaitMs = passContext.settings && passContext.settings.maxWaitForLoad;

Expand Down Expand Up @@ -876,7 +876,7 @@ class Driver {
}

/**
* @return {Promise<void>}
* @return {Promise<LH.Trace>}
*/
endTrace() {
return new Promise((resolve, reject) => {
Expand All @@ -893,6 +893,7 @@ class Driver {

/**
* @param {LH.Crdp.Tracing.TracingCompleteEvent} traceCompleteEvent
* @return {Promise<LH.Trace>}
*/
_readTraceFromStream(traceCompleteEvent) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -955,7 +956,7 @@ class Driver {
}

/**
* @param {LH.ConfigSettings} settings
* @param {LH.Config.Settings} settings
* @return {Promise<void>}
*/
async beginEmulation(settings) {
Expand All @@ -967,7 +968,7 @@ class Driver {
}

/**
* @param {LH.ConfigSettings} settings
* @param {LH.Config.Settings} settings
* @param {{useThrottling?: boolean}} passConfig
* @return {Promise<void>}
*/
Expand Down Expand Up @@ -998,7 +999,7 @@ class Driver {

/**
* Enable internet connection, using emulated mobile settings if applicable.
* @param {{settings: LH.ConfigSettings, passConfig: LH.ConfigPass}} options
* @param {{settings: LH.Config.Settings, passConfig: LH.Config.Pass}} options
* @return {Promise<void>}
*/
async goOnline(options) {
Expand All @@ -1019,17 +1020,15 @@ class Driver {
}

/**
* @param {LH.Crdp.Network.Headers} headers key/value pairs of HTTP Headers.
* @param {LH.Crdp.Network.Headers=} headers key/value pairs of HTTP Headers.
* @return {Promise<void>}
*/
setExtraHTTPHeaders(headers) {
if (headers) {
return this.sendCommand('Network.setExtraHTTPHeaders', {
headers,
});
async setExtraHTTPHeaders(headers) {
if (!headers) {
return;
}

return Promise.resolve();
return this.sendCommand('Network.setExtraHTTPHeaders', {headers});
}

/**
Expand Down
Loading