Skip to content

Commit

Permalink
Add a DEFAULT_TRACE
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Jul 15, 2016
1 parent f8f3432 commit f96ce3b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 21 deletions.
9 changes: 9 additions & 0 deletions lighthouse-core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
*/
'use strict';

const DEFAULT_TRACE = 'defaultPass';

class Audit {
/**
* @return {!String}
*/
static get DEFAULT_TRACE() {
return DEFAULT_TRACE;
}

/**
* @return {!AuditMeta}
*/
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const Formatter = require('../formatters/formatter');
// https://www.desmos.com/calculator/srv0hqhf7d
const SCORING_POINT_OF_DIMINISHING_RETURNS = 50;
const SCORING_MEDIAN = 100;
const TRACE_NAME = 'firstPass';

class EstimatedInputLatency extends Audit {
/**
Expand All @@ -51,7 +50,8 @@ class EstimatedInputLatency extends Audit {
// Use speedline's first paint as start of range for input latency check.
const startTime = artifacts.Speedline.first;

const trace = artifacts.traces[TRACE_NAME] && artifacts.traces[TRACE_NAME].traceContents;
const trace = artifacts.traces[this.DEFAULT_TRACE] &&
artifacts.traces[this.DEFAULT_TRACE].traceContents;
const tracingProcessor = new TracingProcessor();
const model = tracingProcessor.init(trace);
const latencyPercentiles = TracingProcessor.getRiskToResponsiveness(model, trace, startTime);
Expand Down
4 changes: 1 addition & 3 deletions lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const SCORING_MEDIAN = 4000;

const BLOCK_FIRST_MEANINGFUL_PAINT_IF_BLANK_CHARACTERS_MORE_THAN = 200;

const TRACE_NAME = 'firstPass';

class FirstMeaningfulPaint extends Audit {
/**
* @return {!AuditMeta}
Expand All @@ -54,7 +52,7 @@ class FirstMeaningfulPaint extends Audit {
*/
static audit(artifacts) {
return new Promise((resolve, reject) => {
const traceContents = artifacts.traces[TRACE_NAME].traceContents;
const traceContents = artifacts.traces[this.DEFAULT_TRACE].traceContents;
if (!traceContents || !Array.isArray(traceContents)) {
throw new Error(FAILURE_MESSAGE);
}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/user-timings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const Formatter = require('../formatters/formatter');
const TimelineModel = require('../lib/traces/devtools-timeline-model');

const FAILURE_MESSAGE = 'Trace data not found.';
const TRACE_NAME = 'firstPass';

/**
* @param {!Array<!Object>} traceData
Expand Down Expand Up @@ -130,7 +129,8 @@ class UserTimings extends Audit {
static audit(artifacts) {
return new Promise((resolve, reject) => {
const traceContents =
artifacts.traces[TRACE_NAME] && artifacts.traces[TRACE_NAME].traceContents;
artifacts.traces[this.DEFAULT_TRACE] &&
artifacts.traces[this.DEFAULT_TRACE].traceContents;
if (!traceContents || !Array.isArray(traceContents)) {
throw new Error(FAILURE_MESSAGE);
}
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"passes": [{
"network": true,
"trace": true,
"traceName": "firstPass",
"loadPage": true,
"gatherers": [
"url",
Expand Down
8 changes: 3 additions & 5 deletions lighthouse-core/driver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
'use strict';

class Driver {
const Audit = require('../audits/audit');

class Driver {
static loadPage(driver, options) {
// Since a Page.reload command does not let a service worker take over, we
// navigate away and then come back to reload. We do not `waitForLoad` on
Expand Down Expand Up @@ -165,10 +166,7 @@ class Driver {
.then(_ => this.afterPass(runOptions))
.then(loadData => {
Object.assign(tracingData, loadData);

if (config.traceName) {
tracingData.traces[config.traceName] = loadData;
}
tracingData.traces[config.traceName || Audit.DEFAULT_TRACE] = loadData;
})
.then(_ => this.tearDown(runOptions));
}, Promise.resolve());
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const traceContents = require('../fixtures/traces/progressive-app.json');
describe('Performance: estimated-input-latency audit', () => {
it('scores a -1 with invalid trace data', () => {
const output = Audit.audit({
traces: {firstPass: {traceContents: '[{"pid": 15256,"tid": 1295,"t'}},
traces: {[Audit.DEFAULT_TRACE]: {traceContents: '[{"pid": 15256,"tid": 1295,"t'}},
Speedline: {
first: 500
}
Expand All @@ -35,7 +35,7 @@ describe('Performance: estimated-input-latency audit', () => {

it('evaluates valid input correctly', () => {
const output = Audit.audit({
traces: {firstPass: {traceContents}},
traces: {[Audit.DEFAULT_TRACE]: {traceContents}},
Speedline: {
first: 500
}
Expand Down
9 changes: 5 additions & 4 deletions lighthouse-core/test/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ describe('Performance: first-meaningful-paint audit', () => {
it('processes a valid trace file', done => {
const traceData = require('../fixtures/traces/progressive-app.json');
assert.doesNotThrow(_ => {
Audit.audit({traces: {firstPass: {traceContents: traceData}}}).then(response => {
fmpResult = response;
done();
});
Audit.audit({traces: {[Audit.DEFAULT_TRACE]: {traceContents: traceData}}})
.then(response => {
fmpResult = response;
done();
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/user-timing.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Performance: user-timings audit', () => {
});

it('evaluates valid input correctly', () => {
return Audit.audit({traces: {firstPass: {traceContents}}})
return Audit.audit({traces: {[Audit.DEFAULT_TRACE]: {traceContents}}})
.then(response => {
assert.equal(response.score, 2);
assert.ok(!Number.isNaN(response.extendedInfo.value[0].startTime));
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
const Runner = require('../runner');
const fakeDriver = require('./driver/fake-driver');
const Config = require('../config');
const Audit = require('../audits/audit');
const assert = require('assert');
const path = require('path');

Expand Down Expand Up @@ -87,7 +88,7 @@ describe('Runner', () => {

artifacts: {
traces: {
firstPass: {
[Audit.DEFAULT_TRACE]: {
traceContents: path.join(__dirname,
'/fixtures/traces/trace-user-timings.json')
}
Expand Down

0 comments on commit f96ce3b

Please sign in to comment.