Skip to content

Commit

Permalink
fix(hook): Don't exit with non-zero code on error (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ta2edchimp authored and Kent C. Dodds committed Apr 12, 2016
1 parent 48d4794 commit 4fe533c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 51 deletions.
8 changes: 5 additions & 3 deletions lib/hook.template.raw
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const fs = require('fs')
const path = require('path')
const ghooks = getGhooksEntryPoint()

checkForGHooks(ghooks)
require(ghooks)(__dirname, __filename)
if (checkForGHooks(ghooks)) {
require(ghooks)(__dirname, __filename)
}

function getGhooksEntryPoint() {
const worktree = getWorkTree()
Expand All @@ -21,8 +22,9 @@ function checkForGHooks(ghooksPath) {
require(ghooksPath)
} catch (e) {
warnAboutGHooks()
process.exit(1)
return false
}
return true
}

function getWorkTree() {
Expand Down
52 changes: 4 additions & 48 deletions test/hook.template.raw.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,8 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
describe('when ghooks is not found', () => {
it('warns about ghooks not being present', sinon.test(function test() {
const warn = this.stub(console, 'warn')
const exitMessage = 'Exit process when ghooks not being present'
// instead of really exiting the process ...
const exit = this.stub(process, 'exit', () => {
// ... throw a predetermined exception, thus preventing
// further code execution within the tested module ...
throw Error(exitMessage)
})
// ... and expect it to be eventually thrown
expect(() => {
proxyquire('../lib/hook.template.raw', {ghooks: null})
}).to.throw(exitMessage)
proxyquire('../lib/hook.template.raw', {ghooks: null})
expect(warn).to.have.been.calledWithMatch(/ghooks not found!/i)
expect(exit).to.have.been.calledWith(1)
}))

})
Expand Down Expand Up @@ -76,19 +65,8 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
},
}
const warn = this.stub(console, 'warn')
const exitMessage = 'Exit process when ghooks not being present'
// instead of really exiting the process ...
const exit = this.stub(process, 'exit', () => {
// ... throw a predetermined exception, thus preventing
// further code execution within the tested module ...
throw Error(exitMessage)
})
// ... and expect it to be eventually thrown
expect(() => {
proxyquire('../lib/hook.template.raw', stub)
}).to.throw(exitMessage)
proxyquire('../lib/hook.template.raw', stub)
expect(warn).to.have.been.calledWithMatch(/ghooks not found!/i)
expect(exit).to.have.been.calledWith(1)
}))

it('warns about ghooks not being found due to no gitdir being present', sinon.test(function test() {
Expand All @@ -102,19 +80,8 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
},
}
const warn = this.stub(console, 'warn')
const exitMessage = 'Exit process when ghooks not being present'
// instead of really exiting the process ...
const exit = this.stub(process, 'exit', () => {
// ... throw a predetermined exception, thus preventing
// further code execution within the tested module ...
throw Error(exitMessage)
})
// ... and expect it to be eventually thrown
expect(() => {
proxyquire('../lib/hook.template.raw', stub)
}).to.throw(exitMessage)
proxyquire('../lib/hook.template.raw', stub)
expect(warn).to.have.been.calledWithMatch(/ghooks not found!/i)
expect(exit).to.have.been.calledWith(1)
}))

it('warns about ghooks not being found due to no valid git config being present', sinon.test(function test() {
Expand All @@ -127,19 +94,8 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
},
}
const warn = this.stub(console, 'warn')
const exitMessage = 'Exit process when ghooks not being present'
// instead of really exiting the process ...
const exit = this.stub(process, 'exit', () => {
// ... throw a predetermined exception, thus preventing
// further code execution within the tested module ...
throw Error(exitMessage)
})
// ... and expect it to be eventually thrown
expect(() => {
proxyquire('../lib/hook.template.raw', stub)
}).to.throw(exitMessage)
proxyquire('../lib/hook.template.raw', stub)
expect(warn).to.have.been.calledWithMatch(/ghooks not found!/i)
expect(exit).to.have.been.calledWith(1)
}))

})
Expand Down

0 comments on commit 4fe533c

Please sign in to comment.