Skip to content

Commit

Permalink
core(tsc): add type checking to runner (#4961)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Apr 13, 2018
1 parent 6d6af51 commit cd2d36e
Show file tree
Hide file tree
Showing 15 changed files with 430 additions and 264 deletions.
14 changes: 14 additions & 0 deletions lighthouse-core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ class Audit {
return {};
}

/* eslint-disable no-unused-vars */

/**
*
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {LH.Audit.Product|Promise<LH.Audit.Product>}
*/
static audit(artifacts, context) {
throw new Error('audit() method must be overriden');
}

/* eslint-enable no-unused-vars */

/**
* Computes a clamped score between 0 and 1 based on the measured value. Score is determined by
* considering a log-normal distribution governed by the two control points, point of diminishing
Expand Down
7 changes: 6 additions & 1 deletion lighthouse-core/audits/seo/robots-txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class RobotsTxt extends Audit {
}

/**
* @param {{RobotsTxt: {status: number, content: string}}} artifacts
* @param {LH.Artifacts} artifacts
* @return {LH.Audit.Product}
*/
static audit(artifacts) {
Expand Down Expand Up @@ -198,6 +198,11 @@ class RobotsTxt extends Audit {
};
}

// If status is good, content must be not null.
if (content === null) {
throw new Error(`Status ${status} was valid, but content was null`);
}

const validationErrors = validateRobots(content);

const headings = [
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function assertValidAudit(auditDefinition, auditPath) {
const auditName = auditPath ||
(auditDefinition && auditDefinition.meta && auditDefinition.meta.name);

if (typeof auditDefinition.audit !== 'function') {
if (typeof auditDefinition.audit !== 'function' || auditDefinition.audit === Audit.audit) {
throw new Error(`${auditName} has no audit() method.`);
}

Expand Down
6 changes: 5 additions & 1 deletion lighthouse-core/lib/asset-saver.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ async function prepareAssets(artifacts, audits) {
for (const passName of passNames) {
const trace = artifacts.traces[passName];
const devtoolsLog = artifacts.devtoolsLogs[passName];

// Avoid Runner->AssetSaver->Runner circular require by loading Runner here.
const Runner = require('../runner.js');
const computedArtifacts = Runner.instantiateComputedArtifacts();
/** @type {Array<Screenshot>} */
// @ts-ignore TODO(bckenny): need typed computed artifacts
const screenshots = await artifacts.requestScreenshots(trace);
const screenshots = await computedArtifacts.requestScreenshots(trace);

const traceData = Object.assign({}, trace);
const screenshotsHTML = screenshotDump(screenshots);
Expand Down
Loading

0 comments on commit cd2d36e

Please sign in to comment.