Skip to content

Commit

Permalink
Merge pull request #1088 from GoogleChrome/artifacterrors
Browse files Browse the repository at this point in the history
add check for requiredArtifacts before running audits
  • Loading branch information
brendankenny committed Dec 2, 2016
2 parents e5089e3 + 14ce7bf commit 6943b99
Show file tree
Hide file tree
Showing 61 changed files with 236 additions and 357 deletions.
7 changes: 3 additions & 4 deletions lighthouse-core/audits/cache-start-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CacheStartUrl extends Audit {
*/
static audit(artifacts) {
let cacheHasStartUrl = false;
const manifest = artifacts.Manifest && artifacts.Manifest.value;
const manifest = artifacts.Manifest.value;
const cacheContents = artifacts.CacheContents;

if (!(manifest && manifest.start_url && manifest.start_url.value)) {
Expand All @@ -48,11 +48,10 @@ class CacheStartUrl extends Audit {
});
}

if (!(Array.isArray(cacheContents) && artifacts.URL &&
artifacts.URL.finalUrl)) {
if (!Array.isArray(cacheContents)) {
return CacheStartUrl.generateAuditResult({
rawValue: false,
debugString: 'No cache or URL detected'
debugString: cacheContents.debugString || 'No cache detected'
});
}

Expand Down
14 changes: 3 additions & 11 deletions lighthouse-core/audits/content-width.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@ class ContentWidth extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.ContentWidth === 'undefined' ||
typeof artifacts.ContentWidth.scrollWidth === 'undefined' ||
typeof artifacts.ContentWidth.viewportWidth === 'undefined') {
return ContentWidth.generateAuditResult({
rawValue: false,
debugString: 'Unable to find scroll and viewport widths.'
});
}

const widthsMatch =
artifacts.ContentWidth.scrollWidth === artifacts.ContentWidth.viewportWidth;
const scrollWidth = artifacts.ContentWidth.scrollWidth;
const viewportWidth = artifacts.ContentWidth.viewportWidth;
const widthsMatch = scrollWidth === viewportWidth && scrollWidth !== -1;

return ContentWidth.generateAuditResult({
rawValue: widthsMatch,
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/audits/dobetterweb/appcache-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class AppCacheManifestAttr extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.AppCacheManifest === 'undefined' ||
artifacts.AppCacheManifest === -1) {
if (artifacts.AppCacheManifest === -1) {
return AppCacheManifestAttr.generateAuditResult({
rawValue: false,
debugString: 'Unable to determine if you\'re using AppCache.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class ExternalAnchorsUseRelNoopenerAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.AnchorsWithNoRelNoopener === 'undefined' ||
artifacts.AnchorsWithNoRelNoopener === -1) {
if (artifacts.AnchorsWithNoRelNoopener === -1) {
return ExternalAnchorsUseRelNoopenerAudit.generateAuditResult({
rawValue: -1,
debugString: 'AnchorsWithNoRelNoopener gatherer did not run'
debugString: 'Unknown error with the AnchorsWithNoRelNoopener gatherer.'
});
}

Expand Down
7 changes: 2 additions & 5 deletions lighthouse-core/audits/dobetterweb/geolocation-on-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ class GeolocationOnStart extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.GeolocationOnStart === 'undefined' ||
artifacts.GeolocationOnStart.value === -1) {
if (artifacts.GeolocationOnStart.value === -1) {
let debugString = 'Unknown error with the GeolocationOnStart gatherer';
if (typeof artifacts.GeolocationOnStart === 'undefined') {
debugString = 'GeolocationOnStart gatherer did not run';
} else if (artifacts.GeolocationOnStart.debugString) {
if (artifacts.GeolocationOnStart.debugString) {
debugString = artifacts.GeolocationOnStart.debugString;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class LinkBlockingFirstPaintAudit extends Audit {
*/
static computeAuditResultForTags(artifacts, tagFilter) {
const artifact = artifacts.TagsBlockingFirstPaint;
if (typeof artifact === 'undefined' || artifact.value === -1) {
if (artifact.value === -1) {
return {
rawValue: -1,
debugString: 'TagsBlockingFirstPaint gatherer did not run'
debugString: artifact.debugString
};
}

Expand Down
7 changes: 2 additions & 5 deletions lighthouse-core/audits/dobetterweb/no-console-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ class NoConsoleTimeAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.ConsoleTimeUsage === 'undefined' ||
artifacts.ConsoleTimeUsage.value === -1) {
if (artifacts.ConsoleTimeUsage.value === -1) {
let debugString = 'Unknown error with the ConsoleTimeUsage gatherer';
if (typeof artifacts.ConsoleTimeUsage === 'undefined') {
debugString = 'ConsoleTimeUsage gatherer did not run';
} else if (artifacts.ConsoleTimeUsage.debugString) {
if (artifacts.ConsoleTimeUsage.debugString) {
debugString = artifacts.ConsoleTimeUsage.debugString;
}

Expand Down
7 changes: 2 additions & 5 deletions lighthouse-core/audits/dobetterweb/no-datenow.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ class NoDateNowAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.DateNowUse === 'undefined' ||
artifacts.DateNowUse.value === -1) {
if (artifacts.DateNowUse.value === -1) {
let debugString = 'Unknown error with the DateNowUse gatherer';
if (typeof artifacts.DateNowUse === 'undefined') {
debugString = 'DateNowUse gatherer did not run';
} else if (artifacts.DateNowUse.debugString) {
if (artifacts.DateNowUse.debugString) {
debugString = artifacts.DateNowUse.debugString;
}

Expand Down
7 changes: 2 additions & 5 deletions lighthouse-core/audits/dobetterweb/no-document-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ class NoDocWriteAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.DocWriteUse === 'undefined' ||
artifacts.DocWriteUse.value === -1) {
if (artifacts.DocWriteUse.value === -1) {
let debugString = 'Unknown error with the DocWriteUse gatherer';
if (typeof artifacts.DocWriteUse === 'undefined') {
debugString = 'DocWriteUse gatherer did not run';
} else if (artifacts.DocWriteUse.debugString) {
if (artifacts.DocWriteUse.debugString) {
debugString = artifacts.DocWriteUse.debugString;
}

Expand Down
8 changes: 1 addition & 7 deletions lighthouse-core/audits/dobetterweb/no-mutation-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ class NoMutationEventsAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.EventListeners === 'undefined' ||
artifacts.EventListeners === -1) {
return NoMutationEventsAudit.generateAuditResult({
rawValue: -1,
debugString: 'EventListeners gatherer did not run'
});
} else if (artifacts.EventListeners.rawValue === -1) {
if (artifacts.EventListeners.rawValue === -1) {
return NoMutationEventsAudit.generateAuditResult(artifacts.EventListeners);
}

Expand Down
7 changes: 1 addition & 6 deletions lighthouse-core/audits/dobetterweb/no-old-flexbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ class NoOldFlexboxAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.Styles === 'undefined') {
return NoOldFlexboxAudit.generateAuditResult({
rawValue: -1,
debugString: 'Styles gatherer did not run'
});
} else if (artifacts.Styles.rawValue === -1) {
if (artifacts.Styles.rawValue === -1) {
return NoOldFlexboxAudit.generateAuditResult(artifacts.Styles);
}

Expand Down
6 changes: 2 additions & 4 deletions lighthouse-core/audits/dobetterweb/no-websql.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ class NoWebSQLAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.WebSQL === 'undefined' ||
artifacts.WebSQL.database === -1) {
if (artifacts.WebSQL.database === -1) {
return NoWebSQLAudit.generateAuditResult({
rawValue: -1,
debugString: (artifacts.WebSQL ?
artifacts.WebSQL.debugString : 'WebSQL gatherer did not run')
debugString: artifacts.WebSQL.debugString
});
}

Expand Down
7 changes: 2 additions & 5 deletions lighthouse-core/audits/dobetterweb/notification-on-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ class NotificationOnStart extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.NotificationOnStart === 'undefined' ||
artifacts.NotificationOnStart.value === -1) {
if (artifacts.NotificationOnStart.value === -1) {
let debugString = 'Unknown error with the NotificationOnStart gatherer';
if (typeof artifacts.NotificationOnStart === 'undefined') {
debugString = 'NotificationOnStart gatherer did not run';
} else if (artifacts.NotificationOnStart.debugString) {
if (artifacts.NotificationOnStart.debugString) {
debugString = artifacts.NotificationOnStart.debugString;
}

Expand Down
8 changes: 0 additions & 8 deletions lighthouse-core/audits/dobetterweb/uses-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ class UsesHTTP2Audit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.networkRecords === 'undefined' ||
artifacts.URL === 'undefined') {
return UsesHTTP2Audit.generateAuditResult({
rawValue: -1,
debugString: 'Network or URL gatherer did not run'
});
}

const networkRecords = artifacts.networkRecords[Audit.DEFAULT_PASS];
const finalHost = url.parse(artifacts.URL.finalUrl).host;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ class PassiveEventsAudit extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (typeof artifacts.EventListeners === 'undefined' ||
artifacts.EventListeners === -1) {
return PassiveEventsAudit.generateAuditResult({
rawValue: -1,
debugString: 'EventListeners gatherer did not run'
});
} else if (artifacts.EventListeners.rawValue === -1) {
if (artifacts.EventListeners.rawValue === -1) {
return PassiveEventsAudit.generateAuditResult(artifacts.EventListeners);
}

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EstimatedInputLatency extends Audit {
description: 'Estimated Input Latency',
optimalValue: SCORING_POINT_OF_DIMINISHING_RETURNS.toLocaleString() + 'ms',
helpText: 'The score above is an estimate of how long your app takes to respond to user input, in milliseconds. There is a 90% probability that a user encounters this amount of latency, or less. 10% of the time a user can expect additional latency. If your score is higher than Lighthouse\'s target score, users may perceive your app as laggy. <a href="https://developers.google.com/web/tools/lighthouse/audits/estimated-input-latency" rel="noopener noreferrer" target="_blank">Learn more</a>.',
requiredArtifacts: ['traceContents']
requiredArtifacts: ['traces']
};
}

Expand Down
7 changes: 1 addition & 6 deletions lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const Audit = require('./audit');
const TracingProcessor = require('../lib/traces/tracing-processor');
const Formatter = require('../formatters/formatter');

const FAILURE_MESSAGE = 'Navigation and first paint timings not found.';

// Parameters (in ms) for log-normal CDF scoring. To see the curve:
// https://www.desmos.com/calculator/joz3pqttdq
const SCORING_POINT_OF_DIMINISHING_RETURNS = 1600;
Expand All @@ -39,7 +37,7 @@ class FirstMeaningfulPaint extends Audit {
description: 'First meaningful paint',
optimalValue: SCORING_POINT_OF_DIMINISHING_RETURNS.toLocaleString() + 'ms',
helpText: 'First meaningful paint measures when the primary content of a page is visible. <a href="https://developers.google.com/web/tools/lighthouse/audits/first-meaningful-paint" target="_blank" rel="noreferrer noopener">Learn more</a>.',
requiredArtifacts: ['traceContents']
requiredArtifacts: ['traces']
};
}

Expand All @@ -53,9 +51,6 @@ class FirstMeaningfulPaint extends Audit {
static audit(artifacts) {
return new Promise((resolve, reject) => {
const traceContents = artifacts.traces[this.DEFAULT_PASS].traceEvents;
if (!traceContents || !Array.isArray(traceContents)) {
throw new Error(FAILURE_MESSAGE);
}
const evts = this.collectEvents(traceContents);

const navStart = evts.navigationStart;
Expand Down
7 changes: 0 additions & 7 deletions lighthouse-core/audits/redirects-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ class RedirectsHTTP extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (!artifacts.HTTPRedirect ||
!artifacts.HTTPRedirect.value) {
return RedirectsHTTP.generateAuditResult({
rawValue: false
});
}

return RedirectsHTTP.generateAuditResult({
rawValue: artifacts.HTTPRedirect.value,
debugString: artifacts.HTTPRedirect.debugString
Expand Down
8 changes: 1 addition & 7 deletions lighthouse-core/audits/screenshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Screenshots extends Audit {
category: 'Performance',
name: 'screenshots',
description: 'Screenshots of all captured frames',
requiredArtifacts: ['traceContents']
requiredArtifacts: ['traces']
};
}

Expand All @@ -39,12 +39,6 @@ class Screenshots extends Audit {
*/
static audit(artifacts) {
const trace = artifacts.traces[this.DEFAULT_PASS];
if (typeof trace === 'undefined') {
return Promise.resolve(Screenshots.generateAuditResult({
rawValue: -1,
debugString: 'No trace found to generate screenshots'
}));
}

return artifacts.requestScreenshots(trace).then(screenshots => {
if (typeof screenshots === 'undefined') {
Expand Down
8 changes: 1 addition & 7 deletions lighthouse-core/audits/speed-index-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SpeedIndexMetric extends Audit {
description: 'Perceptual Speed Index',
helpText: 'Speed Index shows how quickly the contents of a page are visibly populated. <a href="https://developers.google.com/web/tools/lighthouse/audits/speed-index" target="_blank" rel="noreferrer noopener">Learn more</a>.',
optimalValue: SCORING_POINT_OF_DIMINISHING_RETURNS.toLocaleString(),
requiredArtifacts: ['traceContents']
requiredArtifacts: ['traces']
};
}

Expand All @@ -49,12 +49,6 @@ class SpeedIndexMetric extends Audit {
*/
static audit(artifacts) {
const trace = artifacts.traces[this.DEFAULT_PASS];
if (typeof trace === 'undefined') {
return SpeedIndexMetric.generateAuditResult({
rawValue: -1,
debugString: 'No trace found to generate screenshots'
});
}

// run speedline
return artifacts.requestSpeedline(trace).then(speedline => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/theme-color-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ThemeColor extends Audit {
*/
static audit(artifacts) {
const themeColorMeta = artifacts.ThemeColor;
if (!themeColorMeta) {
if (themeColorMeta === null || themeColorMeta === -1) {
return ThemeColor.generateAuditResult({
rawValue: false,
debugString: 'No valid theme-color meta tag found.'
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/time-to-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TTIMetric extends Audit {
description: 'Time To Interactive (alpha)',
helpText: 'Time to Interactive identifies the time at which your app appears to be ready enough to interact with. <a href="https://developers.google.com/web/tools/lighthouse/audits/time-to-interactive" target="_blank" rel="noopener noreferrer">Learn more</a>.',
optimalValue: SCORING_TARGET.toLocaleString() + 'ms',
requiredArtifacts: ['traceContents']
requiredArtifacts: ['traces']
};
}

Expand Down
10 changes: 1 addition & 9 deletions lighthouse-core/audits/user-timings.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class UserTimings extends Audit {
name: 'user-timings',
description: 'User Timing marks and measures',
helpText: 'Consider instrumenting your app with the User Timing API to create custom, real-world measurements of key user experiences. <a href="https://developers.google.com/web/tools/lighthouse/audits/user-timing" target="_blank" rel="noreferrer noopener">Learn more</a>.',
requiredArtifacts: ['traceContents']
requiredArtifacts: ['traces']
};
}

Expand All @@ -128,14 +128,6 @@ class UserTimings extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
if (!artifacts.traces || !artifacts.traces[Audit.DEFAULT_PASS] ||
!Array.isArray(artifacts.traces[Audit.DEFAULT_PASS].traceEvents)) {
return UserTimings.generateAuditResult({
rawValue: -1,
debugString: 'Trace data not found.'
});
}

const traceContents = artifacts.traces[Audit.DEFAULT_PASS].traceEvents;
const userTimings = filterTrace(traceContents);

Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/audits/without-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class WithoutJavaScript extends Audit {
*/
static audit(artifacts) {
const artifact = artifacts.HTMLWithoutJavaScript;
if (!artifact || typeof artifact.value !== 'string') {
if (typeof artifact.value !== 'string') {
return WithoutJavaScript.generateAuditResult({
rawValue: -1,
debugString: (artifact && artifact.debugString) ||
'HTMLWithoutJavaScript gatherer did not complete successfully'
debugString: artifact.debugString ||
'HTMLWithoutJavaScript gatherer did not complete successfully'
});
}

Expand Down

0 comments on commit 6943b99

Please sign in to comment.