From 8eb6cce4b3622bf2180de5b6c54f8ecebef205be Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Thu, 11 Jan 2018 18:13:43 +0100 Subject: [PATCH] fix: Make console unavailable in sandbox hooks under node >= 8 Addressing https://github.com/apiaryio/pitboss/issues/13 Close https://github.com/apiaryio/dredd/issues/754 --- src/transaction-runner.coffee | 9 +++++++++ test/unit/transaction-runner-test.coffee | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/transaction-runner.coffee b/src/transaction-runner.coffee index cdd2b3d2e..b63580c35 100644 --- a/src/transaction-runner.coffee +++ b/src/transaction-runner.coffee @@ -197,6 +197,15 @@ class TransactionRunner sandboxedWrappedCode: (hookCode) -> return """ + // make console unavailable + try { + // node >= 8 + console = undefined; + } catch (_exc) { + // node < 8 + var console = undefined; + } + // run the hook var log = _log.bind(null, _logs); diff --git a/test/unit/transaction-runner-test.coffee b/test/unit/transaction-runner-test.coffee index 0133474da..8dcdd41bd 100644 --- a/test/unit/transaction-runner-test.coffee +++ b/test/unit/transaction-runner-test.coffee @@ -2468,5 +2468,5 @@ describe 'TransactionRunner', -> """ runner.runHook hook, {}, (err) -> assert.isDefined err - assert.include err, 'console' + assert.include err, 'Cannot read property \'log\' of undefined' done()