Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't exit with non-zero code on error #80

Merged
merged 1 commit into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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