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

Fixes #1069 - remove scores from perf metrics. Change to pass/fail. #1072

Merged
merged 1 commit into from
Nov 28, 2016
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
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 @@ -61,7 +61,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 @@ -127,27 +125,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