diff --git a/lighthouse-core/audits/audit.js b/lighthouse-core/audits/audit.js index c32c5d194820..cc41d8cd2e30 100644 --- a/lighthouse-core/audits/audit.js +++ b/lighthouse-core/audits/audit.js @@ -16,7 +16,16 @@ */ 'use strict'; +const DEFAULT_TRACE = 'defaultPass'; + class Audit { + /** + * @return {!String} + */ + static get DEFAULT_TRACE() { + return DEFAULT_TRACE; + } + /** * @return {!AuditMeta} */ diff --git a/lighthouse-core/audits/estimated-input-latency.js b/lighthouse-core/audits/estimated-input-latency.js index 3cc9300a1cf7..2223b19dbc34 100644 --- a/lighthouse-core/audits/estimated-input-latency.js +++ b/lighthouse-core/audits/estimated-input-latency.js @@ -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 { /** @@ -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); diff --git a/lighthouse-core/audits/first-meaningful-paint.js b/lighthouse-core/audits/first-meaningful-paint.js index 58626486371b..20737af9fbb6 100644 --- a/lighthouse-core/audits/first-meaningful-paint.js +++ b/lighthouse-core/audits/first-meaningful-paint.js @@ -30,8 +30,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} @@ -55,7 +53,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); } diff --git a/lighthouse-core/audits/time-to-interactive.js b/lighthouse-core/audits/time-to-interactive.js index 95e1fa8d3842..3e769804e5eb 100644 --- a/lighthouse-core/audits/time-to-interactive.js +++ b/lighthouse-core/audits/time-to-interactive.js @@ -68,7 +68,8 @@ class TTIMetric extends Audit { // Process the trace const tracingProcessor = new TracingProcessor(); - const model = tracingProcessor.init(artifacts.traceContents); + const traceContents = artifacts.traces[Audit.DEFAULT_TRACE].traceContents; + const model = tracingProcessor.init(traceContents); const endOfTraceTime = model.bounds.max; // TODO: Wait for DOMContentLoadedEndEvent @@ -109,7 +110,7 @@ class TTIMetric extends Audit { } // Get our expected latency for the time window const latencies = TracingProcessor.getRiskToResponsiveness( - model, artifacts.traceContents, startTime, endTime, percentiles); + model, traceContents, startTime, endTime, percentiles); const estLatency = latencies[0].time.toFixed(2); foundLatencies.push({ estLatency: estLatency, diff --git a/lighthouse-core/audits/user-timings.js b/lighthouse-core/audits/user-timings.js index 3deedde2c88a..f4c1d17b9105 100644 --- a/lighthouse-core/audits/user-timings.js +++ b/lighthouse-core/audits/user-timings.js @@ -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} traceData @@ -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); } diff --git a/lighthouse-core/config/default.json b/lighthouse-core/config/default.json index d08bbd9520e9..637d07faef27 100644 --- a/lighthouse-core/config/default.json +++ b/lighthouse-core/config/default.json @@ -2,7 +2,6 @@ "passes": [{ "network": true, "trace": true, - "traceName": "firstPass", "loadPage": true, "gatherers": [ "url", diff --git a/lighthouse-core/driver/gatherers/screenshots.js b/lighthouse-core/driver/gatherers/screenshots.js index b8e630a5b74d..db6c9fed5851 100644 --- a/lighthouse-core/driver/gatherers/screenshots.js +++ b/lighthouse-core/driver/gatherers/screenshots.js @@ -18,6 +18,7 @@ 'use strict'; const Gather = require('./gather'); +const Audit = require('../../audits/audit'); const DevtoolsTimelineModel = require('../../lib/traces/devtools-timeline-model'); class ScreenshotFilmstrip extends Gather { @@ -46,7 +47,7 @@ class ScreenshotFilmstrip extends Gather { } afterPass(options, tracingData) { - return this.getScreenshots(tracingData.traceContents) + return this.getScreenshots(tracingData.traces[Audit.DEFAULT_TRACE].traceContents) .then(screenshots => { this.artifact = screenshots; }); diff --git a/lighthouse-core/driver/gatherers/speedline.js b/lighthouse-core/driver/gatherers/speedline.js index 7b7b233215a0..5c31d9d5a5b3 100644 --- a/lighthouse-core/driver/gatherers/speedline.js +++ b/lighthouse-core/driver/gatherers/speedline.js @@ -16,19 +16,20 @@ */ 'use strict'; +const Audit = require('../../audits/audit'); const Gather = require('./gather'); const speedline = require('speedline'); class Speedline extends Gather { - afterPass(options, tracingData) { - return speedline(tracingData.traceContents).then(results => { - this.artifact = results; - }).catch(err => { - this.artifact = { - debugString: err.message - }; - }); + return speedline(tracingData.traces[Audit.DEFAULT_TRACE].traceContents) + .then(results => { + this.artifact = results; + }).catch(err => { + this.artifact = { + debugString: err.message + }; + }); } } diff --git a/lighthouse-core/driver/index.js b/lighthouse-core/driver/index.js index 77d0a20b9cac..274a9f711a5c 100644 --- a/lighthouse-core/driver/index.js +++ b/lighthouse-core/driver/index.js @@ -17,9 +17,9 @@ 'use strict'; const log = require('../lib/log.js'); +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 @@ -107,15 +107,19 @@ class Driver { const driver = options.driver; const config = options.config; const gatherers = config.gatherers; - const loadData = {}; + const loadData = {traces: {}}; let pass = Promise.resolve(); if (config.trace) { pass = pass.then(_ => { - log.log('status', 'Gathering: trace'); + let traceName = Audit.DEFAULT_TRACE; + if (config.traceName) { + traceName = config.traceName; + } + log.log('status', `Gathering: trace "${traceName}"`); driver.endTrace().then(traceContents => { - loadData.traceContents = traceContents; - log.log('statusEnd', 'Gathering: trace'); + loadData.traces[traceName] = {traceContents}; + log.log('statusEnd', `Gathering: trace "${traceName}"`); }); }); } @@ -191,10 +195,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()); diff --git a/lighthouse-core/test/audits/estimated-input-latency.js b/lighthouse-core/test/audits/estimated-input-latency.js index c823b7c8890b..9d87a40b2d7e 100644 --- a/lighthouse-core/test/audits/estimated-input-latency.js +++ b/lighthouse-core/test/audits/estimated-input-latency.js @@ -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 } @@ -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 } diff --git a/lighthouse-core/test/audits/first-meaningful-paint.js b/lighthouse-core/test/audits/first-meaningful-paint.js index 39d4fb10a835..2332b7320402 100644 --- a/lighthouse-core/test/audits/first-meaningful-paint.js +++ b/lighthouse-core/test/audits/first-meaningful-paint.js @@ -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(); + }); }); }); diff --git a/lighthouse-core/test/audits/time-to-interactive.js b/lighthouse-core/test/audits/time-to-interactive.js index fbe5a3d1b59a..fcd36a163378 100644 --- a/lighthouse-core/test/audits/time-to-interactive.js +++ b/lighthouse-core/test/audits/time-to-interactive.js @@ -26,7 +26,11 @@ const speedlineGather = new SpeedlineGather(); describe('Performance: time-to-interactive audit', () => { it('scores a -1 with invalid trace data', () => { return Audit.audit({ - traceContents: '[{"pid": 15256,"tid": 1295,"t', + traces: { + [Audit.DEFAULT_TRACE]: { + traceContents: '[{"pid": 15256,"tid": 1295,"t' + } + }, Speedline: { first: 500 } @@ -38,7 +42,11 @@ describe('Performance: time-to-interactive audit', () => { it('evaluates valid input correctly', () => { let artifacts = { - traceContents: traceContents + traces: { + [Audit.DEFAULT_TRACE]: { + traceContents: traceContents + } + } }; return speedlineGather.afterPass({}, artifacts).then(_ => { artifacts.Speedline = speedlineGather.artifact; diff --git a/lighthouse-core/test/audits/user-timing.js b/lighthouse-core/test/audits/user-timing.js index 2ae911c7a304..29f2fa1f51b6 100644 --- a/lighthouse-core/test/audits/user-timing.js +++ b/lighthouse-core/test/audits/user-timing.js @@ -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)); diff --git a/lighthouse-core/test/driver/gatherers/screenshots.js b/lighthouse-core/test/driver/gatherers/screenshots.js index 39e2f4a69434..42e13dd00b5f 100644 --- a/lighthouse-core/test/driver/gatherers/screenshots.js +++ b/lighthouse-core/test/driver/gatherers/screenshots.js @@ -18,6 +18,7 @@ /* eslint-env mocha */ const ScreenshotsGather = require('../../../driver/gatherers/screenshots'); +const Audit = require('../../../audits/audit'); const assert = require('assert'); let screenshotsGather = new ScreenshotsGather(); @@ -27,7 +28,13 @@ describe('Screenshot gatherer', () => { // Currently this test must rely on knowing the phase hook for the gatherer. // A little unfortunate, but we need a "run scheduler with this gatherer, this mocked driver, // and this trace" test class to do that right - return screenshotsGather.afterPass(undefined, {traceContents: traceData}).then(_ => { + return screenshotsGather.afterPass(undefined, { + traces: { + [Audit.DEFAULT_TRACE]: { + traceContents: traceData + } + } + }).then(_ => { assert.ok(Array.isArray(screenshotsGather.artifact)); assert.equal(screenshotsGather.artifact.length, 7); diff --git a/lighthouse-core/test/driver/gatherers/speedline.js b/lighthouse-core/test/driver/gatherers/speedline.js index d3b6bfccbda5..18d529744302 100644 --- a/lighthouse-core/test/driver/gatherers/speedline.js +++ b/lighthouse-core/test/driver/gatherers/speedline.js @@ -17,6 +17,7 @@ /* eslint-env mocha */ +const Audit = require('../../../audits/audit.js'); const SpeedlineGather = require('../../../driver/gatherers/speedline.js'); const assert = require('assert'); @@ -24,7 +25,13 @@ describe('Speedline gatherer', () => { it('returns an error debugString on faulty trace data', done => { const speedlineGather = new SpeedlineGather(); - speedlineGather.afterPass({}, {traceContents: {boo: 'ya'}}).then(_ => { + speedlineGather.afterPass({}, { + traces: { + [Audit.DEFAULT_TRACE]: { + traceContents: {boo: 'ya'} + } + } + }).then(_ => { assert.ok(speedlineGather.artifact.debugString); assert.ok(speedlineGather.artifact.debugString.length); done(); @@ -36,7 +43,13 @@ describe('Speedline gatherer', () => { const speedlineGather = new SpeedlineGather(); const traceContents = require('../../fixtures/traces/progressive-app.json'); - return speedlineGather.afterPass({}, {traceContents}).then(_ => { + return speedlineGather.afterPass({}, { + traces: { + [Audit.DEFAULT_TRACE]: { + traceContents + } + } + }).then(_ => { const speedline = speedlineGather.artifact; return assert.equal(Math.round(speedline.speedIndex), 831); }); diff --git a/lighthouse-core/test/driver/index.js b/lighthouse-core/test/driver/index.js index ecee0a61c496..7fa7f712ffdc 100644 --- a/lighthouse-core/test/driver/index.js +++ b/lighthouse-core/test/driver/index.js @@ -20,6 +20,7 @@ const Gather = require('../../driver/gatherers/gather'); const Driver = require('../../driver'); +const Audit = require('../../audits/audit'); const assert = require('assert'); class TestGatherer extends Gather { @@ -159,7 +160,27 @@ describe('Driver', function() { return Driver.afterPass({driver, config}).then(vals => { assert.equal(calledTrace, true); - assert.deepEqual(vals.traceContents, {x: 1}); + assert.deepEqual(vals.traces[Audit.DEFAULT_TRACE].traceContents, {x: 1}); + }); + }); + + it('respects trace names', () => { + const driver = { + endTrace() { + return Promise.resolve({x: 1}); + } + }; + + const config = { + trace: true, + traceName: 'notTheDefaultPass', + gatherers: [{ + afterPass() {} + }] + }; + + return Driver.afterPass({driver, config}).then(vals => { + assert.deepEqual(vals.traces.notTheDefaultPass.traceContents, {x: 1}); }); }); diff --git a/lighthouse-core/test/runner.js b/lighthouse-core/test/runner.js index 2cb31eb8e221..315427ef9053 100644 --- a/lighthouse-core/test/runner.js +++ b/lighthouse-core/test/runner.js @@ -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'); @@ -87,7 +88,7 @@ describe('Runner', () => { artifacts: { traces: { - firstPass: { + [Audit.DEFAULT_TRACE]: { traceContents: path.join(__dirname, '/fixtures/traces/trace-user-timings.json') }