Skip to content

Commit ac2f62d

Browse files
committed
remove redundant gatherer lifecycle methods
1 parent 7ffa0c9 commit ac2f62d

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

lighthouse-core/gather/drivers/driver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class Driver {
247247
return resolve();
248248
}
249249

250-
this.on('Page.loadEventFired', response => {
250+
this.once('Page.loadEventFired', response => {
251251
setTimeout(_ => {
252252
resolve(response);
253253
}, this.PAUSE_AFTER_LOAD);

lighthouse-core/gather/gather-runner.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ class GatherRunner {
5151
});
5252
}
5353

54-
static setup(options) {
54+
static setupPass(options) {
5555
const driver = options.driver;
5656
const config = options.config;
57-
const gatherers = config.gatherers;
5857
let pass = Promise.resolve();
5958

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

68-
return gatherers.reduce((chain, gatherer) => {
69-
return chain.then(_ => gatherer.setup(options));
70-
}, pass);
67+
return pass;
7168
}
7269

7370
static beforePass(options) {
@@ -160,14 +157,6 @@ class GatherRunner {
160157
.then(_ => loadData);
161158
}
162159

163-
static tearDown(options) {
164-
const config = options.config;
165-
const gatherers = config.gatherers;
166-
return gatherers.reduce((chain, gatherer) => {
167-
return chain.then(_ => gatherer.tearDown(options));
168-
}, Promise.resolve());
169-
}
170-
171160
static run(passes, options) {
172161
const driver = options.driver;
173162
const tracingData = {traces: {}};
@@ -200,16 +189,15 @@ class GatherRunner {
200189
return passes.reduce((chain, config) => {
201190
const runOptions = Object.assign({}, options, {config});
202191
return chain
203-
.then(_ => this.setup(runOptions))
192+
.then(_ => this.setupPass(runOptions))
204193
.then(_ => this.beforePass(runOptions))
205194
.then(_ => this.pass(runOptions))
206195
.then(_ => this.afterPass(runOptions))
207196
.then(loadData => {
208197
// Merge pass trace and network data into tracingData.
209198
config.trace && Object.assign(tracingData.traces, loadData.traces);
210199
config.network && (tracingData.networkRecords = loadData.networkRecords);
211-
})
212-
.then(_ => this.tearDown(runOptions));
200+
});
213201
}, Promise.resolve());
214202
})
215203
.then(_ => {

lighthouse-core/gather/gatherers/gatherer.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,27 @@ class Gatherer {
3434

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

37-
setup(options) { }
38-
37+
/**
38+
* Called before navigation to target url.
39+
* @param {!Object} options
40+
*/
3941
beforePass(options) { }
4042

43+
/**
44+
* Called after target page is loaded. If a trace is enabled for this pass,
45+
* the trace is still being recorded.
46+
* @param {!Object} options
47+
*/
4148
pass(options) { }
4249

43-
afterPass(options) { }
44-
45-
tearDown(options) { }
50+
/**
51+
* Called after target page is loaded, all gatherer `pass` methods have been
52+
* executed, and — if generated in this pass — the trace is ended. The trace
53+
* and record of network activity are provided in `loadData`.
54+
* @param {!Object} options
55+
* @param {{networkRecords: !Array, traceEvents: !Array} loadData
56+
*/
57+
afterPass(options, loadData) { }
4658

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

lighthouse-core/test/gather/gather-runner.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestGatherer extends Gatherer {
3333
return 'test';
3434
}
3535

36-
setup() {
36+
pass() {
3737
this.called = true;
3838
}
3939
}
@@ -132,12 +132,10 @@ describe('GatherRunner', function() {
132132

133133
const config = {
134134
trace: true,
135-
gatherers: [{
136-
setup() {}
137-
}]
135+
gatherers: [{}]
138136
};
139137

140-
return GatherRunner.setup({driver, config}).then(_ => {
138+
return GatherRunner.setupPass({driver, config}).then(_ => {
141139
assert.equal(calledTrace, true);
142140
});
143141
});
@@ -195,12 +193,10 @@ describe('GatherRunner', function() {
195193

196194
const config = {
197195
network: true,
198-
gatherers: [{
199-
setup() {}
200-
}]
196+
gatherers: [{}]
201197
};
202198

203-
return GatherRunner.setup({driver, config}).then(_ => {
199+
return GatherRunner.setupPass({driver, config}).then(_ => {
204200
assert.equal(calledNetworkCollect, true);
205201
});
206202
});

0 commit comments

Comments
 (0)