From 61f030dd7323abcc7eb2c25c46e8e06cc8a9e4cf Mon Sep 17 00:00:00 2001 From: nicojs Date: Tue, 12 Jul 2016 07:28:28 +0200 Subject: [PATCH] fix(log4jsMock): Restore sandbox in log4js mock For the log4js mock, it is nessesery to restore it after each test run in order to clean in for the next one (if there is a next one) --- test/helpers/log4jsMock.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/helpers/log4jsMock.ts b/test/helpers/log4jsMock.ts index 0692d51315..bc988680ef 100644 --- a/test/helpers/log4jsMock.ts +++ b/test/helpers/log4jsMock.ts @@ -1,7 +1,7 @@ +console.log('l4js:', require.resolve('log4js')); import * as log4js from 'log4js'; import * as sinon from 'sinon'; -const l = log4js.getLogger(); let logger = { isTraceEnabled: sinon.stub(), trace: sinon.stub(), @@ -16,8 +16,10 @@ let logger = { isFatalEnabled: sinon.stub(), fatal: sinon.stub() }; +let sandbox = sinon.sandbox.create(); -sinon.stub(log4js, 'getLogger').returns(logger); +// Stub away even before other files are loaded and tests have started +sandbox.stub(log4js, 'getLogger').returns(logger); beforeEach(() => { logger.trace.reset(); @@ -28,4 +30,9 @@ beforeEach(() => { logger.fatal.reset(); }); +after( () => { + // Restore for next (stryker) test run + sandbox.restore(); +}); + export default logger; \ No newline at end of file