test(commits): initial suite

This commit is contained in:
Stephan Bönnemann 2015-06-14 18:08:16 -07:00
parent f62525ad7e
commit d6172b8767
2 changed files with 41 additions and 0 deletions

View File

@ -25,6 +25,7 @@
"mkdirp": "^0.5.1",
"nock": "^2.5.0",
"nyc": "^2.3.0",
"proxyquire": "^1.5.0",
"rimraf": "^2.4.0",
"semver": "^4.3.6",
"standard": "^4.2.1",

40
test/specs/commits.js Normal file
View File

@ -0,0 +1,40 @@
const test = require('tap').test
const proxyquire = require('proxyquire')
const rawCommits = [
'hash-one==SPLIT==commit-one==END==\n',
'hash-two==SPLIT==commit-two==END==\n'
]
const commits = proxyquire('../../dist/lib/commits.js', {
'child_process': {
exec: (command, cb) => {
cb(
null,
/\.\.HEAD/.test(command) ?
rawCommits[0] :
rawCommits.join()
)
},
'@noCallThru': true
}
})
test('commits since last release', (t) => {
t.test('get all commits', (t) => {
commits({lastRelease: {}}, (err, commits) => {
t.error(err)
t.is(commits.length, 2, 'all commits')
t.is(commits[0].hash, 'hash-one', 'parsed hash')
t.is(commits[1].message, 'commit-two', 'parsed message')
})
})
t.test('get commits since hash', (t) => {
commits({lastRelease: {gitHead: 'hash'}}, (err, commits) => {
t.error(err)
t.is(commits.length, 1, 'specified commits')
t.is(commits[0].hash, 'hash-one', 'parsed hash')
t.is(commits[0].message, 'commit-one', 'parsed message')
})
})
})