Skip to content

Commit

Permalink
feat(bootstrap): add ability to load adapterConfig from bootstrap
Browse files Browse the repository at this point in the history
* feat(cli): add ability to load adapterConfig from bootstrap

Instead of forcing the commitizen config to be loaded via a file (package.json, .czrc, .cz.json)
this adds a way to inject an adapterConfig into the bootstrap function. We use this internally at
Autodesk to wrap the cli so that each of our repos doesn't need to have the commitizen config

* test(cli): add tests for providing adapterConfig via bootstrap function

* add proxyquire & sinon to aid unit testing
* excludes src/cli from nyc since most of it is not unit-tested and this
  test causes coverage to be misreported
  • Loading branch information
Cameron Westland authored and jimthedev committed Apr 20, 2016
1 parent a538dce commit c6d2fdb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@
"node-uuid": "1.4.7",
"nodemon": "1.9.1",
"nyc": "6.4.0",
"proxyquire": "^1.7.4",
"rimraf": "2.5.2",
"semantic-release": "^4.3.5",
"semver": "5.1.0"
"semver": "5.1.0",
"sinon": "^1.17.3"
},
"dependencies": {
"chalk": "1.1.3",
Expand All @@ -84,5 +86,12 @@
"es2015",
"stage-2"
]
},

"nyc": {
"exclude": [
"src/cli",
"test"
]
}
}
7 changes: 3 additions & 4 deletions src/cli/git-cz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ function bootstrap(environment = {}) {

// Get cli args
let rawGitArgs = process.argv.slice(2, process.argv.length);

// Load the adapter config
let adapterConfig = configLoader.load();


let adapterConfig = environment.config || configLoader.load();

// Choose a strategy based on the existance the adapter config
if(typeof adapterConfig !== 'undefined') {
// This tells commitizen we're in business
Expand Down
59 changes: 59 additions & 0 deletions test/tests/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {expect} from 'chai';
import proxyquire from 'proxyquire';
import * as sinon from 'sinon';

describe('git-cz', () => {
let bootstrap;
let fakeStrategies, fakeCommitizen;

beforeEach(() => {
fakeStrategies = {
git: sinon.spy(),
gitCz: sinon.spy()
}

fakeCommitizen = {
configLoader: {
load: sinon.stub()
}
}

bootstrap = proxyquire('../../src/cli/git-cz', {
'./strategies': fakeStrategies,
'../commitizen': fakeCommitizen
}).bootstrap;
});

describe('bootstrap', () => {
describe('when config is provided', () => {
it('passes config to useGitCzStrategy', () => {
const config = sinon.spy();

bootstrap({ config });

expect(fakeStrategies.gitCz.args[0][2]).to.equal(config);
});
});

describe('when config is not provided', () => {

describe('and the config is returned from configLoader.load', () => {
it('uses config from configLoader.load()', () => {
const config = sinon.stub();
fakeCommitizen.configLoader.load.returns(config);

bootstrap({});

expect(fakeStrategies.gitCz.args[0][2]).to.equal(config);
});
});

describe('and the config is not returned from configLoader.load', () => {
it('tells commitizen to use the git strategy', () => {
bootstrap({});
expect(fakeStrategies.git.called).to.equal(true);
});
});
});
});
});
1 change: 1 addition & 0 deletions test/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './adapter';
import './cli';
import './commit';
import './configLoader';
import './init';
Expand Down

0 comments on commit c6d2fdb

Please sign in to comment.