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(artifacts): create a PublicGathererArtifacts type #8382

Merged
merged 5 commits into from
Apr 18, 2019
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
2 changes: 1 addition & 1 deletion lighthouse-cli/test/cli/__snapshots__/index-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ Object {
"path": "runtime-exceptions",
},
Object {
"path": "chrome-console-messages",
"path": "console-messages",
},
Object {
"path": "anchor-elements",
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Deprecations extends Audit {
failureTitle: 'Uses deprecated APIs',
description: 'Deprecated APIs will eventually be removed from the browser. ' +
'[Learn more](https://www.chromestatus.com/features#deprecated).',
requiredArtifacts: ['ChromeConsoleMessages'],
requiredArtifacts: ['ConsoleMessages'],
};
}

Expand All @@ -34,7 +34,7 @@ class Deprecations extends Audit {
* @return {LH.Audit.Product}
*/
static audit(artifacts) {
const entries = artifacts.ChromeConsoleMessages;
const entries = artifacts.ConsoleMessages;

const deprecations = entries.filter(log => log.entry.source === 'deprecation').map(log => {
return {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/dobetterweb/geolocation-on-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GeolocationOnStart extends ViolationAudit {
description: 'Users are mistrustful of or confused by sites that request their ' +
'location without context. Consider tying the request to user gestures instead. ' +
'[Learn more](https://developers.google.com/web/tools/lighthouse/audits/geolocation-on-load).',
requiredArtifacts: ['ChromeConsoleMessages'],
requiredArtifacts: ['ConsoleMessages'],
};
}

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/dobetterweb/no-document-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NoDocWriteAudit extends ViolationAudit {
description: 'For users on slow connections, external scripts dynamically injected via ' +
'`document.write()` can delay page load by tens of seconds. ' +
'[Learn more](https://developers.google.com/web/tools/lighthouse/audits/document-write).',
requiredArtifacts: ['ChromeConsoleMessages'],
requiredArtifacts: ['ConsoleMessages'],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NotificationOnStart extends ViolationAudit {
description: 'Users are mistrustful of or confused by sites that request to send ' +
'notifications without context. Consider tying the request to user gestures ' +
'instead. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/notifications-on-load).',
requiredArtifacts: ['ChromeConsoleMessages'],
requiredArtifacts: ['ConsoleMessages'],
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PassiveEventsAudit extends ViolationAudit {
description: 'Consider marking your touch and wheel event listeners as `passive` ' +
'to improve your page\'s scroll performance. ' +
'[Learn more](https://developers.google.com/web/tools/lighthouse/audits/passive-event-listeners).',
requiredArtifacts: ['ChromeConsoleMessages'],
requiredArtifacts: ['ConsoleMessages'],
};
}

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/errors-in-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ErrorLogs extends Audit {
description: 'Errors logged to the console indicate unresolved problems. ' +
'They can come from network request failures and other browser concerns.',
failureTitle: 'Browser errors were logged to the console',
requiredArtifacts: ['ChromeConsoleMessages', 'RuntimeExceptions'],
requiredArtifacts: ['ConsoleMessages', 'RuntimeExceptions'],
};
}

Expand All @@ -32,7 +32,7 @@ class ErrorLogs extends Audit {
* @return {LH.Audit.Product}
*/
static audit(artifacts) {
const consoleEntries = artifacts.ChromeConsoleMessages;
const consoleEntries = artifacts.ConsoleMessages;
const runtimeExceptions = artifacts.RuntimeExceptions;
/** @type {Array<{source: string, description: string|undefined, url: string|undefined}>} */
const consoleRows =
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/violation-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ViolationAudit extends Audit {
*/
static getViolationResults(artifacts, pattern) {
const seen = new Set();
return artifacts.ChromeConsoleMessages
return artifacts.ConsoleMessages
.map(message => message.entry)
.filter(entry => entry.url && entry.source === 'violation' && pattern.test(entry.text))
.map(entry => ({label: `line: ${entry.lineNumber}`, url: entry.url}))
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const defaultConfig = {
'css-usage',
'viewport-dimensions',
'runtime-exceptions',
'chrome-console-messages',
'console-messages',
'anchor-elements',
'image-elements',
'link-elements',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const Gatherer = require('./gatherer');

class ChromeConsoleMessages extends Gatherer {
class ConsoleMessages extends Gatherer {
constructor() {
super();
/** @type {Array<LH.Crdp.Log.EntryAddedEvent>} */
Expand Down Expand Up @@ -41,7 +41,7 @@ class ChromeConsoleMessages extends Gatherer {

/**
* @param {LH.Gatherer.PassContext} passContext
* @return {Promise<LH.Artifacts['ChromeConsoleMessages']>}
* @return {Promise<LH.Artifacts['ConsoleMessages']>}
*/
async afterPass(passContext) {
await passContext.driver.sendCommand('Log.stopViolationsReport');
Expand All @@ -51,4 +51,4 @@ class ChromeConsoleMessages extends Gatherer {
}
}

module.exports = ChromeConsoleMessages;
module.exports = ConsoleMessages;
6 changes: 3 additions & 3 deletions lighthouse-core/test/audits/deprecations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const assert = require('assert');
describe('Console deprecations audit', () => {
it('passes when no console messages were found', () => {
const auditResult = DeprecationsAudit.audit({
ChromeConsoleMessages: [],
ConsoleMessages: [],
});
assert.equal(auditResult.score, 1);
assert.equal(auditResult.details.items.length, 0);
});

it('handles deprecations that do not have url or line numbers', () => {
const auditResult = DeprecationsAudit.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{
entry: {
source: 'deprecation',
Expand All @@ -41,7 +41,7 @@ describe('Console deprecations audit', () => {
const URL = 'http://example.com';

const auditResult = DeprecationsAudit.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{
entry: {
source: 'deprecation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('UX: geolocation audit', () => {
const text = 'Do not request geolocation permission without a user action.';

const auditResult = GeolocationOnStartAudit.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{entry: {source: 'violation', url: 'https://example.com/', text}},
{entry: {source: 'violation', url: 'https://example2.com/two', text}},
{entry: {source: 'violation', url: 'http://abc.com/', text: 'No document.write'}},
Expand All @@ -28,7 +28,7 @@ describe('UX: geolocation audit', () => {

it('passes when geolocation has not been automatically requested', () => {
const auditResult = GeolocationOnStartAudit.audit({
ChromeConsoleMessages: [],
ConsoleMessages: [],
});
assert.equal(auditResult.score, 1);
assert.equal(auditResult.details.items.length, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const URL = 'https://example.com';
describe('Page does not use document.write()', () => {
it('passes when document.write() is not used', () => {
const auditResult = DocWriteUseAudit.audit({
ChromeConsoleMessages: [],
ConsoleMessages: [],
URL: {finalUrl: URL},
});
assert.equal(auditResult.score, 1);
Expand All @@ -26,7 +26,7 @@ describe('Page does not use document.write()', () => {
const text = 'Do not use document.write';
const auditResult = DocWriteUseAudit.audit({
URL: {finalUrl: URL},
ChromeConsoleMessages: [
ConsoleMessages: [
{entry: {source: 'violation', url: 'https://example.com/', text}},
{entry: {source: 'violation', url: 'https://example2.com/two', text}},
{entry: {source: 'violation', url: 'http://abc.com/', text: 'Long event handler!'}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('UX: notification audit', () => {
it('fails when notification has been automatically requested', () => {
const text = 'Do not request notification permission without a user action.';
const auditResult = NotificationOnStart.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{entry: {source: 'violation', url: 'https://example.com/', text}},
{entry: {source: 'violation', url: 'https://example2.com/two', text}},
{entry: {source: 'violation', url: 'http://abc.com/', text: 'No document.write'}},
Expand All @@ -27,7 +27,7 @@ describe('UX: notification audit', () => {

it('passes when notification has not been automatically requested', () => {
const auditResult = NotificationOnStart.audit({
ChromeConsoleMessages: [],
ConsoleMessages: [],
});
assert.equal(auditResult.score, 1);
assert.equal(auditResult.details.items.length, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Page uses passive events listeners where applicable', () => {
const text = 'Use passive event listeners when you do not use preventDefault';

const auditResult = PassiveEventsAudit.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{entry: {source: 'violation', url: 'https://example.com/', text}},
{entry: {source: 'violation', url: 'https://example2.com/two', text}},
{entry: {source: 'violation', url: 'https://example2.com/two', text}}, // duplicate
Expand All @@ -30,7 +30,7 @@ describe('Page uses passive events listeners where applicable', () => {

it('passes scroll blocking listeners should be passive', () => {
const auditResult = PassiveEventsAudit.audit({
ChromeConsoleMessages: [],
ConsoleMessages: [],
});
assert.equal(auditResult.score, 1);
assert.equal(auditResult.extendedInfo.value.length, 0);
Expand Down
10 changes: 5 additions & 5 deletions lighthouse-core/test/audits/errors-in-console-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const assert = require('assert');
describe('Console error logs audit', () => {
it('passes when no console messages were found', () => {
const auditResult = ErrorLogsAudit.audit({
ChromeConsoleMessages: [],
ConsoleMessages: [],
RuntimeExceptions: [],
});
assert.equal(auditResult.rawValue, 0);
Expand All @@ -24,7 +24,7 @@ describe('Console error logs audit', () => {

it('filter out the non error logs', () => {
const auditResult = ErrorLogsAudit.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{
entry: {
level: 'info',
Expand All @@ -42,7 +42,7 @@ describe('Console error logs audit', () => {

it('fails when error logs are found ', () => {
const auditResult = ErrorLogsAudit.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{
entry: {
level: 'error',
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('Console error logs audit', () => {

it('handle the case when some logs fields are undefined', () => {
const auditResult = ErrorLogsAudit.audit({
ChromeConsoleMessages: [
ConsoleMessages: [
{
entry: {
level: 'error',
Expand All @@ -119,7 +119,7 @@ describe('Console error logs audit', () => {
// Checks bug #4188
it('handle the case when exception info is not present', () => {
const auditResult = ErrorLogsAudit.audit({
ChromeConsoleMessages: [],
ConsoleMessages: [],
RuntimeExceptions: [{
'timestamp': 1506535813608.003,
'exceptionDetails': {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/results/artifacts/artifacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
}
}
],
"ChromeConsoleMessages": [
"ConsoleMessages": [
{
"entry": {
"source": "other",
Expand Down
42 changes: 24 additions & 18 deletions types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,33 @@ declare global {
Timing: Artifacts.MeasureEntry[];
}

/**
* Artifacts provided by the default gatherers that are exposed to plugins with a hardended API.
* NOTE: any breaking changes here are considered breaking Lighthouse changes that must be done
* on a major version bump.
*/
export interface PublicGathererArtifacts {
/** Console deprecation and intervention warnings logged by Chrome during page load. */
ConsoleMessages: Crdp.Log.EntryAddedEvent[];
/** Information on size and loading for all the images in the page. Natural size information for `picture` and CSS images is only available if the image was one of the largest 50 images. */
ImageElements: Artifacts.ImageElement[];
/** All the link elements on the page or equivalently declared in `Link` headers. @see https://html.spec.whatwg.org/multipage/links.html */
LinkElements: Artifacts.LinkElement[];
/** The values of the <meta> elements in the head. */
MetaElements: Array<{name: string, content?: string}>;
/** Set of exceptions thrown during page load. */
RuntimeExceptions: Crdp.Runtime.ExceptionThrownEvent[];
/** Information on all script elements in the page. Also contains the content of all requested scripts and the networkRecord requestId that contained their content. Note, HTML documents will have one entry per script tag, all with the same requestId. */
ScriptElements: Array<Artifacts.ScriptElement>;
/** The dimensions and devicePixelRatio of the loaded viewport. */
ViewportDimensions: Artifacts.ViewportDimensions;
}

/**
* Artifacts provided by the default gatherers. Augment this interface when adding additional
* gatherers.
* gatherers. Changes to these artifacts are not considered a breaking Lighthouse change.
*/
export interface GathererArtifacts {
export interface GathererArtifacts extends PublicGathererArtifacts {
/** The results of running the aXe accessibility tests on the page. */
Accessibility: Artifacts.Accessibility;
/** Array of all anchors on the page. */
Expand All @@ -60,8 +82,6 @@ declare global {
AppCacheManifest: string | null;
/** Array of all URLs cached in CacheStorage. */
CacheContents: string[];
/** Console deprecation and intervention warnings logged by Chrome during page load. */
ChromeConsoleMessages: Crdp.Log.EntryAddedEvent[];
/** CSS coverage information for styles used by page's final state. */
CSSUsage: {rules: Crdp.CSS.RuleUsage[], stylesheets: Artifacts.CSSStyleSheetInfo[]};
/** Information on the document's doctype(or null if not present), specifically the name, publicId, and systemId.
Expand All @@ -71,26 +91,18 @@ declare global {
DOMStats: Artifacts.DOMStats;
/** Relevant attributes and child properties of all <object>s, <embed>s and <applet>s in the page. */
EmbeddedContent: Artifacts.EmbeddedContentInfo[];
/** All the link elements on the page or equivalently declared in `Link` headers. @see https://html.spec.whatwg.org/multipage/links.html */
LinkElements: Artifacts.LinkElement[];
/** Information for font faces used in the page. */
Fonts: Artifacts.Font[];
/** Information on poorly sized font usage and the text affected by it. */
FontSize: Artifacts.FontSize;
/** The hreflang and href values of all link[rel=alternate] nodes found in HEAD. */
Hreflang: {href: string, hreflang: string}[];
/** The page's document body innerText if loaded with JavaScript disabled. */
HTMLWithoutJavaScript: {bodyText: string, hasNoScript: boolean};
/** Whether the page ended up on an HTTPS page after attempting to load the HTTP version. */
HTTPRedirect: {value: boolean};
/** Information on size and loading for all the images in the page. Natural size information for `picture` and CSS images is only available if the image was one of the largest 50 images. */
ImageElements: Artifacts.ImageElement[];
/** JS coverage information for code used during page load. */
JsUsage: Crdp.Profiler.ScriptCoverage[];
/** Parsed version of the page's Web App Manifest, or null if none found. */
Manifest: Artifacts.Manifest | null;
/** The values of the <meta> elements in the head. */
MetaElements: Array<{name: string, content?: string}>;
/** The URL loaded with interception */
MixedContent: {url: string};
/** The status code of the attempted load of the page while network access is disabled. */
Expand All @@ -103,10 +115,6 @@ declare global {
ResponseCompression: {requestId: string, url: string, mimeType: string, transferSize: number, resourceSize: number, gzipSize?: number}[];
/** Information on fetching and the content of the /robots.txt file. */
RobotsTxt: {status: number|null, content: string|null};
/** Set of exceptions thrown during page load. */
RuntimeExceptions: Crdp.Runtime.ExceptionThrownEvent[];
/** Information on all script elements in the page. Also contains the content of all requested scripts and the networkRecord requestId that contained their content. Note, HTML documents will have one entry per script tag, all with the same requestId. */
ScriptElements: Array<Artifacts.ScriptElement>;
/** Version information for all ServiceWorkers active after the first page load. */
ServiceWorker: {versions: Crdp.ServiceWorker.ServiceWorkerVersion[], registrations: Crdp.ServiceWorker.ServiceWorkerRegistration[]};
/** The status of an offline fetch of the page's start_url. -1 and a explanation if missing or there was an error. */
Expand All @@ -115,8 +123,6 @@ declare global {
TagsBlockingFirstPaint: Artifacts.TagBlockingFirstPaint[];
/** Information about tap targets including their position and size. */
TapTargets: Artifacts.TapTarget[];
/** The dimensions and devicePixelRatio of the loaded viewport. */
ViewportDimensions: Artifacts.ViewportDimensions;
}

module Artifacts {
Expand Down