Skip to content

Commit

Permalink
Merge branch 'master' into derived
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 11, 2016
2 parents 137882f + ea23dbd commit 86a7c4c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 53 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
15 changes: 4 additions & 11 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,12 @@ class Runner {
});
}

// Ignoring these two flags since this functionality is not exposed by the module.
// Ignoring these two flags for coverage as this functionality is not exposed by the module.
/* istanbul ignore next */
if (opts.flags.saveArtifacts) {
if (opts.flags.saveArtifacts || opts.flags.saveAssets) {
run = run.then(artifacts => {
assetSaver.saveArtifacts(artifacts);
return artifacts;
});
}

/* istanbul ignore next */
if (opts.flags.saveAssets) {
run = run.then(artifacts => {
assetSaver.saveAssets(opts, artifacts);
opts.flags.saveArtifacts && assetSaver.saveArtifacts(artifacts);
opts.flags.saveAssets && assetSaver.saveAssets(opts, artifacts);
return artifacts;
});
}
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
12 changes: 1 addition & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ cd lighthouse
# will be cleaner soon.
cd lighthouse-core
npm install
cd ../lighthouse-cli/
npm install
# npm link # nah...
# just use `node lighthouse-cli/index.js` for now

# probably very temporary
cd lighthouse-core
npm link
cd ../lighthouse-cli/
npm link lighthouse-core
```

## Custom run configuration
Expand Down Expand Up @@ -160,7 +150,7 @@ The same audits are run against from a Chrome extension. See [./extension](https
_Some incomplete notes_

#### Components
* **Driver** - Interfaces with Chrome Debugging Protocol
* **Driver** - Interfaces with [Chrome Debugging Protocol](https://developer.chrome.com/devtools/docs/debugger-protocol) ([API viewer](https://chromedevtools.github.io/debugger-protocol-viewer/))
* **Gathers** - Requesting data from the browser (and maybe post-processing)
* **Artifacts** - The output of gatherers
* **Audits** - Non-performance evaluations of capabilities and issues. Includes a raw value and score of that value.
Expand Down

0 comments on commit 86a7c4c

Please sign in to comment.