Skip to content

Commit

Permalink
Fixes GoogleChrome#1069 - remove score labels for perf metrics section (
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel authored and andrewrota committed Jan 13, 2017
1 parent c50942f commit 1de9888
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
3 changes: 2 additions & 1 deletion lighthouse-core/audits/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class CriticalRequestChains extends Audit {
walk(chains, 0);

return CriticalRequestChains.generateAuditResult({
rawValue: chainCount,
rawValue: chainCount.length <= this.meta.optimalValue,
displayValue: chainCount,
optimalValue: this.meta.optimalValue,
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.CRITICAL_REQUEST_CHAINS,
Expand Down
35 changes: 15 additions & 20 deletions lighthouse-core/audits/user-timings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const Audit = require('./audit');
const Formatter = require('../formatters/formatter');
const TimelineModel = require('../lib/traces/devtools-timeline-model');

const FAILURE_MESSAGE = 'Trace data not found.';

/**
* @param {!Array<!Object>} traceData
* @return {!Array<!UserTimingsExtendedInfo>}
Expand Down Expand Up @@ -128,27 +126,24 @@ class UserTimings extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
return new Promise((resolve, reject) => {
const traceContents =
artifacts.traces[this.DEFAULT_PASS] &&
artifacts.traces[this.DEFAULT_PASS].traceEvents;
if (!traceContents || !Array.isArray(traceContents)) {
throw new Error(FAILURE_MESSAGE);
}

const userTimings = filterTrace(traceContents);
resolve(UserTimings.generateAuditResult({
rawValue: userTimings.length,
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.USER_TIMINGS,
value: userTimings
}
}));
}).catch(err => {
if (!artifacts.traces || !artifacts.traces[Audit.DEFAULT_PASS] ||
!Array.isArray(artifacts.traces[Audit.DEFAULT_PASS].traceEvents)) {
return UserTimings.generateAuditResult({
rawValue: -1,
debugString: err.message
debugString: 'Trace data not found.'
});
}

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

return UserTimings.generateAuditResult({
rawValue: true,
displayValue: userTimings.length,
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.USER_TIMINGS,
value: userTimings
}
});
}
}
Expand Down
40 changes: 23 additions & 17 deletions lighthouse-core/test/audits/user-timing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,33 @@ const traceEvents = require('../fixtures/traces/trace-user-timings.json');
/* eslint-env mocha */

describe('Performance: user-timings audit', () => {
it('fails gracefully', () => {
return Audit.audit({}).then(response => {
assert.equal(response.score, -1);
assert.ok(response.debugString.length);
});
it('fails when there is no trace data', () => {
const auditResult = Audit.audit({});
assert.equal(auditResult.score, -1);
assert.ok(auditResult.debugString.length);
});

it('fails when trace data is not an array', () => {
const auditResult = Audit.audit({traces: 'not-an-array'});
assert.equal(auditResult.score, -1);
assert.ok(auditResult.debugString);
});

it('evaluates valid input correctly', () => {
return Audit.audit({traces: {[Audit.DEFAULT_PASS]: {traceEvents}}})
.then(response => {
assert.equal(response.score, 2);
const auditResult = Audit.audit({
traces: {[Audit.DEFAULT_PASS]: {traceEvents}}
});
assert.equal(auditResult.score, true);
assert.equal(auditResult.displayValue, 2);

assert.equal(response.extendedInfo.value[0].isMark, true);
assert.equal(Math.floor(response.extendedInfo.value[0].startTime), 1000);
assert.equal(typeof response.extendedInfo.value[0].endTime, 'undefined');
assert.equal(typeof response.extendedInfo.value[0].duration, 'undefined');
assert.equal(auditResult.extendedInfo.value[0].isMark, true);
assert.equal(Math.floor(auditResult.extendedInfo.value[0].startTime), 1000);
assert.equal(typeof auditResult.extendedInfo.value[0].endTime, 'undefined');
assert.equal(typeof auditResult.extendedInfo.value[0].duration, 'undefined');

assert.equal(response.extendedInfo.value[1].isMark, false);
assert.equal(Math.floor(response.extendedInfo.value[1].startTime), 0);
assert.equal(Math.floor(response.extendedInfo.value[1].endTime), 1000);
assert.equal(Math.floor(response.extendedInfo.value[1].duration), 1000);
});
assert.equal(auditResult.extendedInfo.value[1].isMark, false);
assert.equal(Math.floor(auditResult.extendedInfo.value[1].startTime), 0);
assert.equal(Math.floor(auditResult.extendedInfo.value[1].endTime), 1000);
assert.equal(Math.floor(auditResult.extendedInfo.value[1].duration), 1000);
});
});
6 changes: 4 additions & 2 deletions lighthouse-core/test/runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ describe('Runner', () => {

return Runner.run({}, {url, config}).then(results => {
const audits = results.audits;
assert.equal(audits['user-timings'].rawValue, 2);
assert.equal(audits['user-timings'].displayValue, 2);
assert.equal(audits['user-timings'].rawValue, true);
});
});

Expand Down Expand Up @@ -132,7 +133,8 @@ describe('Runner', () => {

return Runner.run({}, {url, config}).then(results => {
const audits = results.audits;
assert.equal(audits['critical-request-chains'].rawValue, 9);
assert.equal(audits['critical-request-chains'].displayValue, 9);
assert.equal(audits['critical-request-chains'].rawValue, false);
});
});

Expand Down

0 comments on commit 1de9888

Please sign in to comment.