From bf6d2dbe27029181487029a8115228171c95980e Mon Sep 17 00:00:00 2001 From: Aleksey Gurianov Date: Sun, 10 Jan 2016 10:49:48 +0000 Subject: [PATCH] feat(commit): allow override options passed to git commit --- src/commitizen/commit.js | 4 +-- test/tests/commit.js | 54 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/commitizen/commit.js b/src/commitizen/commit.js index 1f38d54e..9bb50f54 100644 --- a/src/commitizen/commit.js +++ b/src/commitizen/commit.js @@ -9,10 +9,10 @@ export default commit; function commit(sh, inquirer, repoPath, prompter, options, done) { // Get user input -- side effect that is hard to test - prompter(inquirer, function(template) { + prompter(inquirer, function(template, overrideOptions) { // Commit the user input -- side effect that we'll test - gitCommit(sh, repoPath, template, options, function() { + gitCommit(sh, repoPath, template, { ...options, ...overrideOptions }, function() { done(template); }); }); diff --git a/test/tests/commit.js b/test/tests/commit.js index 5cdea2f2..67a34d59 100644 --- a/test/tests/commit.js +++ b/test/tests/commit.js @@ -133,6 +133,56 @@ describe('commit', function() { }); }); + + it('should allow to override options passed to gulp-git', function(done) { + + this.timeout(config.maxTimeout); // this could take a while + + // SETUP + + let dummyCommitMessage = `sip sip sippin on some sizzurp`; + let author = `A U Thor `; + + // Describe a repo and some files to add and commit + let repoConfig = { + path: config.paths.endUserRepo, + files: { + dummyfile: { + contents: `duck-duck-goose`, + filename: `mydummyfile.txt`, + }, + gitignore: { + contents: `node_modules/`, + filename: `.gitignore` + } + } + }; + + // Describe an adapter + let adapterConfig = { + path: path.join(repoConfig.path, '/node_modules/cz-jira-smart-commit'), + npmName: 'cz-jira-smart-commit' + }; + + let options = { + args: `--author="${author}" --no-edit` + }; + + // Quick setup the repos, adapter, and grab a simple prompter + let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage, options); + // TEST + + // Pass in inquirer but it never gets used since we've mocked out a different + // version of prompter. + commitizenCommit(sh, inquirer, repoConfig.path, prompter, {disableAppendPaths:true, quiet:true, emitData:true}, function() { + log(repoConfig.path, function(logOutput) { + expect(logOutput).to.have.string(author); + expect(logOutput).to.have.string(dummyCommitMessage); + done(); + }); + }); + + }); }); @@ -151,7 +201,7 @@ after(function() { * This is just a helper for testing. NOTE that prompter * prompter is overriden for testing purposes. */ -function quickPrompterSetup(sh, repoConfig, adapterConfig, commitMessage) { +function quickPrompterSetup(sh, repoConfig, adapterConfig, commitMessage, options={}) { commitizenInit(sh, repoConfig.path, adapterConfig.npmName); @@ -160,7 +210,7 @@ function quickPrompterSetup(sh, repoConfig, adapterConfig, commitMessage) { // we'll provide prompter. We'd normally use: // let prompter = getPrompter(adapterConfig.path); let prompter = function(cz, commit) { - commit(commitMessage); + commit(commitMessage, options); } gitInit(sh, repoConfig.path);