Skip to content

Commit

Permalink
remove redundant gatherer lifecycle methods
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Aug 10, 2016
1 parent 7ffa0c9 commit ac2f62d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lighthouse-core/gather/drivers/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Driver {
return resolve();
}

this.on('Page.loadEventFired', response => {
this.once('Page.loadEventFired', response => {
setTimeout(_ => {
resolve(response);
}, this.PAUSE_AFTER_LOAD);
Expand Down
20 changes: 4 additions & 16 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ class GatherRunner {
});
}

static setup(options) {
static setupPass(options) {
const driver = options.driver;
const config = options.config;
const gatherers = config.gatherers;
let pass = Promise.resolve();

if (config.trace) {
Expand All @@ -65,9 +64,7 @@ class GatherRunner {
pass = pass.then(_ => driver.beginNetworkCollect());
}

return gatherers.reduce((chain, gatherer) => {
return chain.then(_ => gatherer.setup(options));
}, pass);
return pass;
}

static beforePass(options) {
Expand Down Expand Up @@ -160,14 +157,6 @@ class GatherRunner {
.then(_ => loadData);
}

static tearDown(options) {
const config = options.config;
const gatherers = config.gatherers;
return gatherers.reduce((chain, gatherer) => {
return chain.then(_ => gatherer.tearDown(options));
}, Promise.resolve());
}

static run(passes, options) {
const driver = options.driver;
const tracingData = {traces: {}};
Expand Down Expand Up @@ -200,16 +189,15 @@ class GatherRunner {
return passes.reduce((chain, config) => {
const runOptions = Object.assign({}, options, {config});
return chain
.then(_ => this.setup(runOptions))
.then(_ => this.setupPass(runOptions))
.then(_ => this.beforePass(runOptions))
.then(_ => this.pass(runOptions))
.then(_ => this.afterPass(runOptions))
.then(loadData => {
// Merge pass trace and network data into tracingData.
config.trace && Object.assign(tracingData.traces, loadData.traces);
config.network && (tracingData.networkRecords = loadData.networkRecords);
})
.then(_ => this.tearDown(runOptions));
});
}, Promise.resolve());
})
.then(_ => {
Expand Down
22 changes: 17 additions & 5 deletions lighthouse-core/gather/gatherers/gatherer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,27 @@ class Gatherer {

/* eslint-disable no-unused-vars */

setup(options) { }

/**
* Called before navigation to target url.
* @param {!Object} options
*/
beforePass(options) { }

/**
* Called after target page is loaded. If a trace is enabled for this pass,
* the trace is still being recorded.
* @param {!Object} options
*/
pass(options) { }

afterPass(options) { }

tearDown(options) { }
/**
* Called after target page is loaded, all gatherer `pass` methods have been
* executed, and — if generated in this pass — the trace is ended. The trace
* and record of network activity are provided in `loadData`.
* @param {!Object} options
* @param {{networkRecords: !Array, traceEvents: !Array} loadData
*/
afterPass(options, loadData) { }

/* eslint-enable no-unused-vars */

Expand Down
14 changes: 5 additions & 9 deletions lighthouse-core/test/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestGatherer extends Gatherer {
return 'test';
}

setup() {
pass() {
this.called = true;
}
}
Expand Down Expand Up @@ -132,12 +132,10 @@ describe('GatherRunner', function() {

const config = {
trace: true,
gatherers: [{
setup() {}
}]
gatherers: [{}]
};

return GatherRunner.setup({driver, config}).then(_ => {
return GatherRunner.setupPass({driver, config}).then(_ => {
assert.equal(calledTrace, true);
});
});
Expand Down Expand Up @@ -195,12 +193,10 @@ describe('GatherRunner', function() {

const config = {
network: true,
gatherers: [{
setup() {}
}]
gatherers: [{}]
};

return GatherRunner.setup({driver, config}).then(_ => {
return GatherRunner.setupPass({driver, config}).then(_ => {
assert.equal(calledNetworkCollect, true);
});
});
Expand Down

0 comments on commit ac2f62d

Please sign in to comment.