From b269b0bd83b1d4641a0be90913399f38c37c1abc Mon Sep 17 00:00:00 2001 From: tormozz48 Date: Tue, 18 Oct 2016 19:03:32 +0300 Subject: [PATCH] feat: Implement readRawConfig static API method --- doc/programmatic-api.md | 4 ++++ lib/config/index.js | 2 ++ lib/gemini.js | 4 ++++ test/unit/config/index.js | 15 +++++++++++++-- test/unit/gemini.js | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/doc/programmatic-api.md b/doc/programmatic-api.md index 15056024d..67a42ca93 100644 --- a/doc/programmatic-api.md +++ b/doc/programmatic-api.md @@ -205,6 +205,10 @@ Rejects promise if critical error occurred. * `gemini.browserIds` – list of all browser identificators to use for tests. +* `Gemini.readRawConfig` - reads configuration file for specified `filePath` +and returns content as JS object. This method does not validate and analyze +gemini configuration. + ## Events `gemini` instance emits some events, which can be used by external scripts or diff --git a/lib/config/index.js b/lib/config/index.js index c51fdaf53..fc1bdad53 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -55,6 +55,8 @@ Config.prototype.isCoverageEnabled = function() { return this.system.coverage.enabled; }; +Config.readRawConfig = readConfig; + function readConfig(filePath) { var config = configReader.read(filePath), configDir = filePath ? path.dirname(filePath) : process.cwd(); diff --git a/lib/gemini.js b/lib/gemini.js index 762483084..3bd5cf433 100644 --- a/lib/gemini.js +++ b/lib/gemini.js @@ -38,6 +38,10 @@ module.exports = class Gemini extends PassthroughEmitter { this._loadPlugins(); } + static readRawConfig(filePath) { + return Config.readRawConfig(filePath); + } + _run(stateProcessor, paths, options) { if (!options) { //if there are only two arguments, they are diff --git a/test/unit/config/index.js b/test/unit/config/index.js index eaf592f43..c489c85a9 100644 --- a/test/unit/config/index.js +++ b/test/unit/config/index.js @@ -18,9 +18,21 @@ describe('config', function() { assert.calledWith(configReader.read, '/some/path'); }); + it('should have static API for reading of a configuration file', () => { + sandbox.stub(configReader, 'read') + .withArgs('/some/path') + .returns({foo: 'bar'}); + + assert.deepEqual(Config.readRawConfig('/some/path'), { + foo: 'bar', + system: { + projectRoot: '/some' + } + }); + }); + describe('overrides', function() { beforeEach(function() { - /*jshint -W069*/ this.configValue = '/from/config'; this.envValue = '/from/env'; this.cliValue = '/from/cli'; @@ -42,7 +54,6 @@ describe('config', function() { }); afterEach(function() { - /*jshint -W069*/ delete process.env['gemini_system_project_root']; process.argv = this.oldArgv; }); diff --git a/test/unit/gemini.js b/test/unit/gemini.js index 2f7bb1b85..7dea17b38 100644 --- a/test/unit/gemini.js +++ b/test/unit/gemini.js @@ -336,4 +336,18 @@ describe('gemini', () => { .then(() => assert.calledWith(console.warn, sinon.match('Unknown browsers id: b2'))); }); }); + + describe('readRawConfig', () => { + beforeEach(() => { + sandbox.stub(Config, 'readRawConfig'); + }); + + it('should read configuration object from file by given path', () => { + Config.readRawConfig + .withArgs('some/file/path') + .returns({foo: 'bar'}); + + assert.deepEqual(Gemini.readRawConfig('some/file/path'), {foo: 'bar'}); + }); + }); });