Skip to content

Commit

Permalink
Move traces to their own subobject
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Jul 6, 2016
1 parent d4ed7fd commit 1c76886
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lighthouse-core/audits/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ 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[TRACE_NAME] && artifacts[TRACE_NAME].traceContents;
const trace = artifacts.traces[TRACE_NAME] && artifacts.traces[TRACE_NAME].traceContents;
const tracingProcessor = new TracingProcessor();
const model = tracingProcessor.init(trace);
const latencyPercentiles = TracingProcessor.getRiskToResponsiveness(model, trace, startTime);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FirstMeaningfulPaint extends Audit {
*/
static audit(artifacts) {
return new Promise((resolve, reject) => {
const traceContents = artifacts[TRACE_NAME].traceContents;
const traceContents = artifacts.traces[TRACE_NAME].traceContents;
if (!traceContents || !Array.isArray(traceContents)) {
throw new Error(FAILURE_MESSAGE);
}
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/user-timings.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class UserTimings extends Audit {
* @return {!AuditResult}
*/
static audit(artifacts) {
const traceContents = artifacts[TRACE_NAME] && artifacts[TRACE_NAME].traceContents;
const traceContents =
artifacts.traces[TRACE_NAME] && artifacts.traces[TRACE_NAME].traceContents;
if (!traceContents || !Array.isArray(traceContents)) {
return UserTimings.generateAuditResult({
value: -1,
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-core/driver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Driver {

static run(passes, options) {
const driver = options.driver;
const tracingData = {};
const tracingData = {traces: {}};

if (typeof options.url !== 'string' || options.url.length === 0) {
return Promise.reject(new Error('You must provide a url to the driver'));
Expand Down Expand Up @@ -169,13 +169,13 @@ class Driver {
if (!config.traceName) {
return;
}
tracingData[config.traceName] = {};
tracingData.traces[config.traceName] = {};
if (config.trace) {
tracingData[config.traceName].traceContents =
tracingData.traces[config.traceName].traceContents =
loadData.traceContents;
}
if (config.network) {
tracingData[config.traceName].networkRecords =
tracingData.traces[config.traceName].networkRecords =
loadData.networkRecords;
}
})
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({
firstPass: {traceContents: '[{"pid": 15256,"tid": 1295,"t'},
traces: {firstPass: {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({
firstPass: {traceContents},
traces: {firstPass: {traceContents}},
Speedline: {
first: 500
}
Expand Down
7 changes: 4 additions & 3 deletions lighthouse-core/test/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ describe('Performance: first-meaningful-paint audit', () => {

it('processes a valid trace file', () => {
const traceData = require('../fixtures/traces/progressive-app.json');
return Audit.audit({firstPass: {traceContents: traceData}}).then(response => {
fmpResult = response;
});
return Audit.audit({traces: {firstPass: {traceContents: traceData}}})
.then(response => {
fmpResult = response;
});
});

it('finds the expected fMP', () => {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/audits/user-timing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const traceContents = require('../fixtures/traces/trace-user-timings.json');

describe('Performance: user-timings audit', () => {
it('fails gracefully', () => {
const output = Audit.audit({});
const output = Audit.audit({traces: {}});
assert.equal(output.value, -1);
});

it('evaluates valid input correctly', () => {
const output = Audit.audit({firstPass: {traceContents}});
const output = Audit.audit({traces: {firstPass: {traceContents}}});
assert.equal(output.value, 2);
assert.ok(!Number.isNaN(output.extendedInfo.value[0].startTime));
assert.ok(typeof output.extendedInfo.value[0].endTime === 'undefined');
Expand Down

0 comments on commit 1c76886

Please sign in to comment.