Skip to content

Commit dec2590

Browse files
committed
Merge pull request #62 from ta2edchimp/follow-up/julien-f-patch-1
Follow up to #50: Exit with error if ghooks is not found
2 parents 931a503 + 427b278 commit dec2590

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/hook.template.raw

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
try {
66
require('ghooks')
77
} catch (e) {
8-
return warnAboutGHooks()
8+
warnAboutGHooks()
9+
process.exit(1)
910
}
1011
require('ghooks')(__dirname, __filename)
1112
})()

test/hook.template.raw.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@ describe('hook.template.raw', function describeHookTemplateRaw() {
2020
describe('when ghooks is not found', () => {
2121
it('warns about ghooks not being present', sinon.test(function test() {
2222
const warn = this.stub(console, 'warn')
23-
proxyquire('../lib/hook.template.raw', {ghooks: null})
23+
const exitMessage = 'Exit process when ghooks not being present'
24+
// instead of really exiting the process ...
25+
const exit = this.stub(process, 'exit', () => {
26+
// ... throw a predetermined exception, thus preventing
27+
// further code execution within the tested module ...
28+
throw Error(exitMessage)
29+
})
30+
// ... and expect it to be eventually thrown
31+
expect(() => {
32+
proxyquire('../lib/hook.template.raw', {ghooks: null})
33+
}).to.throw(exitMessage)
2434
expect(warn).to.have.been.calledWithMatch(/ghooks not found!/i)
35+
expect(exit).to.have.been.calledWith(1)
2536
}))
2637

2738
})

0 commit comments

Comments
 (0)