Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
feat: Implement readRawConfig static API method
Browse files Browse the repository at this point in the history
  • Loading branch information
tormozz48 committed Oct 18, 2016
1 parent 1781b02 commit b269b0b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/programmatic-api.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/config/index.js
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions lib/gemini.js
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions test/unit/config/index.js
Expand Up @@ -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';
Expand All @@ -42,7 +54,6 @@ describe('config', function() {
});

afterEach(function() {
/*jshint -W069*/
delete process.env['gemini_system_project_root'];
process.argv = this.oldArgv;
});
Expand Down
14 changes: 14 additions & 0 deletions test/unit/gemini.js
Expand Up @@ -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'});
});
});
});

0 comments on commit b269b0b

Please sign in to comment.