Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Aug 27, 2016
1 parent f300f67 commit 6add53a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lighthouse-core/audits/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class CriticalRequestChains extends Audit {
* @return {!AuditResult} The score from the audit, ranging from 0-100.
*/
static audit(artifacts) {
const networkRecord = artifacts.networkRecords[Audit.DEFAULT_PASS];
return artifacts.requestCriticalRequestChains(networkRecord).then(chains => {
const networkRecords = artifacts.networkRecords[Audit.DEFAULT_PASS];
return artifacts.requestCriticalRequestChains(networkRecords).then(chains => {
let chainCount = 0;
function walk(node, depth) {
const children = Object.keys(node);
Expand Down
17 changes: 8 additions & 9 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class GatherRunner {
return driver.gotoURL('about:blank')
// Wait a bit for about:blank to "take hold" before switching back to the page.
.then(_ => new Promise((resolve, reject) => setTimeout(resolve, 300)))
// Begin tracing if required.
// Begin tracing only if requested by config.
.then(_ => options.config.trace && driver.beginTrace())
// Begin network recording.
// Network is always recorded for internal use, even if not saved as artifact.
.then(_ => driver.beginNetworkCollect(options))
// Navigate.
.then(_ => driver.gotoURL(options.url, {
Expand Down Expand Up @@ -136,7 +136,7 @@ class GatherRunner {
const driver = options.driver;
const config = options.config;
const gatherers = config.gatherers;
const loadData = {};
const passData = {};

let pass = Promise.resolve();

Expand All @@ -148,9 +148,8 @@ class GatherRunner {
// Before Chrome 54.0.2816 (codereview.chromium.org/2161583004),
// traceContents was an array of trace events; after, traceContents is
// an object with a traceEvents property. Normalize to object form.
loadData.trace = Array.isArray(traceContents) ? {
traceEvents: traceContents
} : traceContents;
passData.trace = Array.isArray(traceContents) ?
{traceEvents: traceContents} : traceContents;
log.verbose('statusEnd', 'Retrieving trace');
});
}
Expand All @@ -161,23 +160,23 @@ class GatherRunner {
return driver.endNetworkCollect();
}).then(networkRecords => {
// Network records only given to gatherers if requested by config.
config.network && (loadData.networkRecords = networkRecords);
config.network && (passData.networkRecords = networkRecords);
log.verbose('statusEnd', status);
});

pass = gatherers.reduce((chain, gatherer) => {
const status = `Retrieving: ${gatherer.name}`;
return chain.then(_ => {
log.log('status', status);
return gatherer.afterPass(options, loadData);
return gatherer.afterPass(options, passData);
}).then(ret => {
log.verbose('statusEnd', status);
return ret;
});
}, pass);

// Resolve on tracing data using passName from config.
return pass.then(_ => loadData);
return pass.then(_ => passData);
}

static run(passes, options) {
Expand Down
7 changes: 4 additions & 3 deletions lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ describe('GatherRunner', function() {

it('tells the driver to end tracing', () => {
let calledTrace = false;
const fakeTraceData = {traceEvents: ['reallyBelievableTraceEvents']};
const driver = {
endTrace() {
calledTrace = true;
return Promise.resolve({x: 1});
return Promise.resolve(fakeTraceData);
},
endNetworkCollect() {
return Promise.resolve();
Expand All @@ -182,9 +183,9 @@ describe('GatherRunner', function() {
}]
};

return GatherRunner.afterPass({driver, config}).then(vals => {
return GatherRunner.afterPass({driver, config}).then(passData => {
assert.equal(calledTrace, true);
assert.deepEqual(vals.trace, {x: 1});
assert.equal(passData.trace, fakeTraceData);
});
});

Expand Down

0 comments on commit 6add53a

Please sign in to comment.