-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add support for --json option
The ```--json``` option returns the result as JSON.stringified array which is pretty useful in combination with the ```--markdown``` option. ``` '[ "+ John Doe <[email protected]> (3 - 50%)", "+ Jane Doe <[email protected]> (3 - 50%)" ]' ```
- Loading branch information
1 parent
0d27512
commit 478f3d7
Showing
3 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* global describe, beforeEach, afterEach */ | ||
/* jshint expr:true, indent:2, maxlen:92 */ | ||
|
||
'use strict'; | ||
|
||
var fs = require('fs'), | ||
sinon = require('sinon'), | ||
chai = require('chai'), | ||
git = require('../lib/gitlog'), | ||
expect = chai.expect, | ||
|
||
GitContributors = require('../').GitContributors; | ||
|
||
|
||
var readIn = function readIn (file) { | ||
return fs.readFileSync(file, 'utf-8'); | ||
}; | ||
|
||
var stubFixture = function stubFixture (file) { | ||
sinon.stub(git, 'log').returns(readIn(file)); | ||
}; | ||
|
||
|
||
describe('git-contributors', function () { | ||
|
||
describe('json support', function () { | ||
|
||
beforeEach(function () { | ||
}); | ||
|
||
afterEach(function () { | ||
git.log.restore(); | ||
}); | ||
|
||
it('--markdown=false --json=true returns a stringified json object', function(done) { | ||
|
||
var inFixture, outFixture; | ||
|
||
inFixture = 'test/fixtures/actual/single-user-multiple-commit.log'; | ||
stubFixture(inFixture); | ||
|
||
outFixture = readIn('test/fixtures/expected/single-user-multiple-commit.json'); | ||
|
||
// beautify string | ||
outFixture = JSON.stringify(JSON.parse(outFixture)); | ||
|
||
GitContributors.list({cwd: '.', markdown: false, json: true}, function (err, result) { | ||
expect(err).to.not.exist; | ||
expect(result).to.deep.eql(outFixture); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('--markdown=true --json=true returns stringified array', function(done) { | ||
|
||
var inFixture, outFixture; | ||
|
||
inFixture = 'test/fixtures/actual/single-user-multiple-commit.log'; | ||
|
||
// outFixture = readIn('test/fixtures/expected/single-user-multiple-commit.md'); | ||
|
||
stubFixture(inFixture); | ||
|
||
outFixture = '["+ John Doe <[email protected]> (3 - 100%)"]'; | ||
|
||
GitContributors.list({cwd: '.', markdown: true, json: true}, function (err, result) { | ||
|
||
expect(err).to.not.exist; | ||
expect(result).to.exist; | ||
expect(result).to.eql(outFixture); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |