From 0da05fb9c6b0a6a799d5336f9d539eebb9913cf4 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Tue, 21 May 2019 18:52:46 +0200 Subject: [PATCH] fix: do not initiate hooks if there are no hookfiles --- lib/addHooks.js | 5 +++++ test/unit/addHooks-test.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/addHooks.js b/lib/addHooks.js index d2ea5b0f5..3b6069c72 100644 --- a/lib/addHooks.js +++ b/lib/addHooks.js @@ -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 { diff --git a/test/unit/addHooks-test.js b/test/unit/addHooks-test.js index 53ada0baf..56d4fa3fd 100644 --- a/test/unit/addHooks-test.js +++ b/test/unit/addHooks-test.js @@ -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( @@ -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); + }); + }); });