Skip to content

Commit

Permalink
Merge pull request #1374 from apiaryio/honzajavorek/fix-empty-hooks
Browse files Browse the repository at this point in the history
Do not initiate hooks if there are no hookfiles
  • Loading branch information
honzajavorek authored May 22, 2019
2 parents 1915116 + 0da05fb commit b7cfb1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/addHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ module.exports = function addHooks(runner, transactions, callback) {
runner.hooks.transactions[transaction.name] = transaction;
});

// No hooks
if (!runner.configuration.hookfiles || !runner.configuration.hookfiles.length) {
return callback();
}

// Loading hookfiles from fs
let hookfiles;
try {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/addHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ describe('addHooks()', () => {

it('sets transactionRunner.hooks.configuation', (done) => {
const transactionRunner = createTransactionRunner();
transactionRunner.configuration.hookfiles = [
'./hooks.js',
];

addHooks(transactionRunner, [], (err) => {
assert.deepEqual(
Expand All @@ -83,4 +86,15 @@ describe('addHooks()', () => {
done(err);
});
});

it('skips hooks loading when there are no hookfiles', (done) => {
const transactionRunner = createTransactionRunner();
transactionRunner.configuration.hookfiles = [];
transactionRunner.configuration.language = 'python';

addHooks(transactionRunner, [], (err) => {
assert.isUndefined(transactionRunner.hooks.configuration);
done(err);
});
});
});

0 comments on commit b7cfb1b

Please sign in to comment.