Skip to content

Commit

Permalink
Adds full report to CLI and extension; upgrades printer.
Browse files Browse the repository at this point in the history
* Refactors for a 'full report' in CLI & extension.
* Upgrades the printer; adds tests.
  • Loading branch information
brendankenny authored and paullewis committed Apr 21, 2016
1 parent 0467666 commit cff829c
Show file tree
Hide file tree
Showing 33 changed files with 1,101 additions and 65 deletions.
9 changes: 9 additions & 0 deletions aggregators/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class Aggregate {
throw new Error('Aggregate name must be overridden');
}

/**
* @throws {Error}
* @return {string} The short name for this aggregation.
*/
static get shortName() {
throw new Error('Aggregate shortName must be overridden');
}

/**
* @throws {Error}
* @return {!AggregationCriteria} The criteria for this aggregation.
Expand Down Expand Up @@ -188,6 +196,7 @@ class Aggregate {
static aggregate(results) {
return {
name: this.name,
shortName: this.shortName,
score: Aggregate.compare(results, this.criteria)
};
}
Expand Down
8 changes: 8 additions & 0 deletions aggregators/can-load-offline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class WorksOffline extends Aggregate {
return 'Works Offline';
}

/**
* @override
* @return {string}
*/
static get shortName() {
return 'Works Offline';
}

/**
* @override
* @return {!AggregationCriteria}
Expand Down
8 changes: 8 additions & 0 deletions aggregators/is-performant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class IsPerformant extends Aggregate {
return 'Is Performant';
}

/**
* @override
* @return {string}
*/
static get shortName() {
return 'Performance';
}

/**
* @override
* @return {!AggregationCriteria}
Expand Down
8 changes: 8 additions & 0 deletions aggregators/is-secure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class IsSecure extends Aggregate {
return 'Is Secure';
}

/**
* @override
* @return {string}
*/
static get shortName() {
return 'Secure';
}

/**
* @override
* @return {!AggregationCriteria}
Expand Down
8 changes: 8 additions & 0 deletions aggregators/is-sized-for-mobile-screen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class MobileFriendly extends Aggregate {
return 'Is Mobile Friendly';
}

/**
* @override
* @return {string}
*/
static get shortName() {
return 'Mobile Friendly';
}

/**
* @override
* @return {!AggregationCriteria}
Expand Down
8 changes: 8 additions & 0 deletions aggregators/launches-with-splash-screen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class SplashScreen extends Aggregate {
return 'Will Launch With A Splash Screen';
}

/**
* @override
* @return {string}
*/
static get shortName() {
return 'Splash Screen';
}

/**
* An app that was installed to homescreen can get a custom splash screen
* while launching.
Expand Down
8 changes: 8 additions & 0 deletions aggregators/omnibox-is-themed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ class OmniboxThemeColor extends Aggregate {
return 'Omnibox Matches Brand Colors';
}

/**
* @override
* @return {string}
*/
static get shortName() {
return 'Omnibox';
}

/**
* For the omnibox to adopt a theme color, Chrome needs the following:
* - has valid manifest
Expand Down
8 changes: 8 additions & 0 deletions aggregators/will-get-add-to-homescreen-prompt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class AddToHomescreen extends Aggregate {
return 'Will Get Add to Homescreen Prompt';
}

/**
* @override
* @return {string}
*/
static get shortName() {
return 'Add to Homescreen';
}

/**
* For the install-to-homescreen / install-app-banner prompt to show,
* Chrome needs the following:
Expand Down
11 changes: 10 additions & 1 deletion audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ class Audit {
throw new Error('Audit description must be overridden');
}

/**
* @return {?(boolean|number|string|undefined)}
*/
static get optimalValue() {
return undefined;
}

/**
* @param {(boolean|number|string)} value
* @param {?(boolean|number|string)=} rawValue
* @param {string=} debugString Optional string to describe any error condition encountered.
* @param {?(boolean|number|string)=} optimalValue
* @return {!AuditResult}
*/
static generateAuditResult(value, rawValue, debugString) {
static generateAuditResult(value, rawValue, debugString, optimalValue) {
return {
value,
rawValue,
debugString,
optimalValue,
name: this.name,
tags: this.tags,
description: this.description
Expand Down
9 changes: 8 additions & 1 deletion audits/performance/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class FirstMeaningfulPaint extends Audit {
return 'Fast first paint of content';
}

/**
* @override
*/
static get optimalValue() {
return '1,000ms';
}

/**
* Audits the page to give a score for First Meaningful Paint.
* @see https://github.com/GoogleChrome/lighthouse/issues/26
Expand Down Expand Up @@ -79,7 +86,7 @@ class FirstMeaningfulPaint extends Audit {
})
.then(result => {
return FirstMeaningfulPaint.generateAuditResult(result.score,
result.duration, result.debugString);
result.duration, result.debugString, this.optimalValue);
});
}
}
Expand Down
15 changes: 12 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ const cli = meow(`
--version Current version of package
--verbose Displays verbose logging
--quiet Displays no progress or debug logs
--json Output results as JSON
--mobile Emulates a Nexus 5X (default=true)
--load-page Loads the page (default=true)
--save-trace Save the trace contents to disk
--output How to output the page(default=pretty)
--output-path The location to output the response(default=stdout)
`);

const defaultUrl = 'https://operasoftware.github.io/pwa-list/';
Expand All @@ -50,8 +51,16 @@ lighthouse({
url: url,
flags: cli.flags
}).then(results => {
Printer[cli.flags.json ? 'json' : 'prettyPrint'](log, console, url, results);
}).catch(err => {
const outputMode = cli.flags.output || 'pretty';
const outputPath = cli.flags.outputPath || 'stdout';
return Printer.write(results, outputMode, outputPath);
})
.then(status => {
if (status) {
log.info('printer', status);
}
})
.catch(err => {
if (err.code === 'ECONNREFUSED') {
console.error('Unable to connect to Chrome. Did you run ./launch-chrome.sh?');
} else {
Expand Down
Loading

0 comments on commit cff829c

Please sign in to comment.