Skip to content

Commit

Permalink
Merge pull request #85 from AndrewSouthpaw/replace-bunyan-with-smalle…
Browse files Browse the repository at this point in the history
…r-logger

Remove logging functionality and drop bunyan dependency.
  • Loading branch information
timkindberg committed Sep 19, 2021
2 parents 8af0e4c + fb72636 commit d591350
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 107 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"Jonas Holtkamp <jonas.holtkamp@senacor.com>"
],
"dependencies": {
"bunyan": "^1.8.12",
"expect": "^24.8.0"
},
"devDependencies": {
Expand Down
14 changes: 0 additions & 14 deletions src/log.js

This file was deleted.

67 changes: 0 additions & 67 deletions src/log.test.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/when.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
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
}

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
Expand Down Expand Up @@ -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]

Expand Down
18 changes: 1 addition & 17 deletions src/when.test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit d591350

Please sign in to comment.