diff --git a/package.json b/package.json index eb3c9135..9a1dcf0c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/specs/commits.js b/test/specs/commits.js new file mode 100644 index 00000000..1b6a1100 --- /dev/null +++ b/test/specs/commits.js @@ -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') + }) + }) +})