fix(commits): add helpful error when lastRelease not in history
Closes #61, Closes #50
This commit is contained in:
@@ -5,6 +5,10 @@ const rawCommits = [
|
||||
|
||||
module.exports = {
|
||||
exec: (command, cb) => {
|
||||
if (/contains/.test(command)) {
|
||||
return cb(null, `whatever\nmaster\n`)
|
||||
}
|
||||
|
||||
cb(
|
||||
null,
|
||||
/\.\.HEAD/.test(command) ?
|
||||
|
||||
+10
-2
@@ -7,7 +7,7 @@ const commits = proxyquire('../../dist/lib/commits', {
|
||||
|
||||
test('commits since last release', (t) => {
|
||||
t.test('get all commits', (tt) => {
|
||||
commits({lastRelease: {}}, (err, commits) => {
|
||||
commits({lastRelease: {}, branch: 'master'}, (err, commits) => {
|
||||
tt.error(err)
|
||||
tt.is(commits.length, 2, 'all commits')
|
||||
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
|
||||
@@ -18,7 +18,7 @@ test('commits since last release', (t) => {
|
||||
})
|
||||
|
||||
t.test('get commits since hash', (tt) => {
|
||||
commits({lastRelease: {gitHead: 'hash'}}, (err, commits) => {
|
||||
commits({lastRelease: {gitHead: 'hash'}, branch: 'master'}, (err, commits) => {
|
||||
tt.error(err)
|
||||
tt.is(commits.length, 1, 'specified commits')
|
||||
tt.is(commits[0].hash, 'hash-one', 'parsed hash')
|
||||
@@ -28,5 +28,13 @@ test('commits since last release', (t) => {
|
||||
})
|
||||
})
|
||||
|
||||
t.test('get commits since hash', (tt) => {
|
||||
commits({lastRelease: {gitHead: 'notinhistory'}, branch: 'notmaster'}, (err, commits) => {
|
||||
tt.ok(err)
|
||||
tt.is(err.code, 'ENOTINHISTORY')
|
||||
tt.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
+6
-3
@@ -3,7 +3,9 @@ const proxyquire = require('proxyquire')
|
||||
|
||||
require('../mocks/registry')
|
||||
const pre = proxyquire('../../dist/pre', {
|
||||
'child_process': require('../mocks/child-process')
|
||||
'./lib/commits': proxyquire('../../dist/lib/commits', {
|
||||
'child_process': require('../mocks/child-process')
|
||||
})
|
||||
})
|
||||
|
||||
const versions = {
|
||||
@@ -14,14 +16,13 @@ const plugins = {
|
||||
verifyRelease: (release, cb) => cb(null, release),
|
||||
analyzeCommits: (commits, cb) => cb(null, 'major'),
|
||||
getLastRelease: ({ pkg }, cb) => {
|
||||
cb(null, { version: versions[pkg.name] || null, gitHead: 'HEAD' })
|
||||
cb(null, {version: versions[pkg.name] || null, gitHead: 'HEAD'})
|
||||
}
|
||||
}
|
||||
|
||||
const npm = {
|
||||
registry: 'http://registry.npmjs.org/',
|
||||
tag: 'latest'
|
||||
|
||||
}
|
||||
|
||||
test('full pre run', (t) => {
|
||||
@@ -29,6 +30,7 @@ test('full pre run', (t) => {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
branch: 'master',
|
||||
npm,
|
||||
pkg: {name: 'available'},
|
||||
plugins
|
||||
@@ -43,6 +45,7 @@ test('full pre run', (t) => {
|
||||
tt.plan(3)
|
||||
|
||||
pre({
|
||||
branch: 'master',
|
||||
npm,
|
||||
pkg: {name: 'unavailable'},
|
||||
plugins
|
||||
|
||||
Reference in New Issue
Block a user