diff --git a/package.json b/package.json index ddb6a0e..06e2c08 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "Jonas Holtkamp " ], "dependencies": { - "bunyan": "^1.8.12", "expect": "^24.8.0" }, "devDependencies": { diff --git a/src/log.js b/src/log.js deleted file mode 100644 index 4e8cb1d..0000000 --- a/src/log.js +++ /dev/null @@ -1,14 +0,0 @@ -const bunyan = require('bunyan') -const packagejson = require('../package.json') -const assert = require('assert') - -const newLogger = name => { - assert(name, 'Name must be defined') - return bunyan.createLogger({ - name: name, - app: packagejson.name, - src: process.env.NODE_ENV === 'development' - }) -} - -module.exports = newLogger diff --git a/src/log.test.js b/src/log.test.js deleted file mode 100644 index 68b7b7a..0000000 --- a/src/log.test.js +++ /dev/null @@ -1,67 +0,0 @@ -const log = require('./log') -const packagejson = require('../package.json') -const { objectContaining } = expect - -describe('the logger', () => { - it('should create new loggers', () => { - const logger = log('name') - - expect(logger.info).toBeDefined() - }) - - it('should use the package json name as the logger app', () => { - const logger = log('name') - - expect(logger.fields.app).toBe(packagejson.name) - }) - - it('should use the name as the loggers name', () => { - const name = 'some name' - - const logger = log(name) - - expect(logger.fields.name).toBe(name) - }) - - it('should fail if no name is passed', () => { - expect(() => log()).toThrow() - }) - - describe('should set "src" to the correct value', () => { - let mockCreateLogger, log - - beforeEach(() => { - mockCreateLogger = jest.fn() - jest.mock('bunyan', () => ({ - createLogger: mockCreateLogger - })) - - log = require('./log') - }) - - afterEach(() => { - jest.resetModules() - jest.resetAllMocks() - }) - - it('should set "src" to true if the stage is development', () => { - const originalValue = process.env.NODE_ENV - process.env.NODE_ENV = 'development' - - log('name') - - process.env.NODE_ENV = originalValue - expect(mockCreateLogger).toBeCalledWith(objectContaining({ src: true })) - }) - - it('should set "src" to false if the stage is NOT development', () => { - const originalValue = process.env.NODE_ENV - process.env.NODE_ENV = 'some other stage' - - log('name') - - process.env.NODE_ENV = originalValue - expect(mockCreateLogger).toBeCalledWith(objectContaining({ src: false })) - }) - }) -}) diff --git a/src/when.js b/src/when.js index 58435e9..39f1742 100644 --- a/src/when.js +++ b/src/when.js @@ -1,14 +1,11 @@ const assert = require('assert') const utils = require('expect/build/jasmineUtils') -const logger = require('./log')('when') let registry = new Set() const getCallLine = () => (new Error()).stack.split('\n')[4] const checkArgumentMatchers = (expectCall, args) => (match, matcher, i) => { - logger.debug(`matcher check, match: ${match}, index: ${i}`) - // Propagate failure to the end if (!match) { return false @@ -16,9 +13,6 @@ const checkArgumentMatchers = (expectCall, args) => (match, matcher, i) => { const arg = args[i] - logger.debug(` matcher: ${String(matcher)}`) - logger.debug(` arg: ${String(arg)}`) - const isFunctionMatcher = typeof matcher === 'function' && matcher._isFunctionMatcher // Assert the match for better messaging during a failure @@ -72,8 +66,6 @@ class WhenMock { this.nextCallMockId++ this.fn.mockImplementation((...args) => { - logger.debug('mocked impl', args) - for (let i = 0; i < this.callMocks.length; i++) { const { matchers, mockImplementation, expectCall, once, called } = this.callMocks[i] diff --git a/src/when.test.js b/src/when.test.js index 64b99ae..506be97 100644 --- a/src/when.test.js +++ b/src/when.test.js @@ -1,25 +1,12 @@ -const { stringContaining } = expect - const errMsg = ({ expect, actual }) => new RegExp(`Expected.*${expect}.*\\nReceived.*${actual}`) describe('When', () => { - let spyEquals, when, WhenMock, mockLogger, resetAllWhenMocks, verifyAllWhenMocksCalled + let spyEquals, when, WhenMock, resetAllWhenMocks, verifyAllWhenMocksCalled beforeEach(() => { spyEquals = jest.spyOn(require('expect/build/jasmineUtils'), 'equals') - mockLogger = { - info: jest.fn(), - debug: jest.fn(), - warn: jest.fn(), - error: jest.fn(), - fatal: jest.fn(), - trace: jest.fn() - } - - jest.mock('./log', () => () => mockLogger) - when = require('./when').when resetAllWhenMocks = require('./when').resetAllWhenMocks verifyAllWhenMocksCalled = require('./when').verifyAllWhenMocksCalled @@ -428,7 +415,6 @@ describe('When', () => { expect(fn(5)).toBeUndefined() expect(fn(symbol, 2)).toBe('x') - expect(mockLogger.debug).toBeCalledWith(stringContaining('matcher: Symbol(sym)')) }) it('returns nothing if no declared value matches', () => { @@ -437,8 +423,6 @@ describe('When', () => { when(fn).calledWith(1, 2).mockReturnValue('x') expect(fn(5, 6)).toBeUndefined() - expect(mockLogger.debug).toBeCalledWith(stringContaining('matcher: 1')) - expect(mockLogger.debug).not.toBeCalledWith(stringContaining('matcher: 2')) }) it('expectCalledWith: fails a test with error messaging if argument does not match', () => {