From a58dc1fab30a3009d667aed473b739e4072b662e Mon Sep 17 00:00:00 2001 From: "jiewei.ljw" Date: Fri, 16 Mar 2018 00:08:03 +0800 Subject: [PATCH] core: look up custom gatherer relative to the config file path (#4751) --- lighthouse-core/config/config.js | 2 +- lighthouse-core/test/config/config-test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index d287a0fa8179..755c45d65af9 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -336,7 +336,7 @@ class Config { // Store the directory of the config path, if one was provided. this._configDir = configPath ? path.dirname(configPath) : undefined; - this._passes = Config.requireGatherers(configJSON.passes); + this._passes = Config.requireGatherers(configJSON.passes, this._configDir); this._audits = Config.requireAudits(configJSON.audits, this._configDir); this._artifacts = expandArtifacts(configJSON.artifacts); this._categories = configJSON.categories; diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index bd262ca22f59..1fd0d9759d79 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -673,6 +673,16 @@ describe('Config', () => { assert.equal(typeof gatherer.instance.beforePass, 'function'); }); + it('loads a gatherer relative to a config path', () => { + const config = new Config({ + passes: [{gatherers: ['../fixtures/valid-custom-gatherer']}], + }, __filename); + const gatherer = config.passes[0].gatherers[0]; + + assert.equal(gatherer.instance.name, 'CustomGatherer'); + assert.equal(typeof gatherer.instance.beforePass, 'function'); + }); + it('returns gatherer when gatherer class, not package-name string, is provided', () => { class TestGatherer extends Gatherer {} const gatherer = loadGatherer(TestGatherer);