2018-06-13 21:58:57 +00:00
|
|
|
const debug = require('debug')
|
|
|
|
const util = require('util')
|
|
|
|
|
|
|
|
debug.recorded = []
|
|
|
|
|
|
|
|
// enable all logs while running the tests
|
|
|
|
debug.enable('thumbsup:*')
|
|
|
|
|
|
|
|
// don't format the logs to avoid any extra ANSI codes
|
|
|
|
debug.formatArgs = function (args) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// capture the logs instead of displaying them
|
|
|
|
debug.log = function () {
|
|
|
|
const message = util.format.apply(null, arguments)
|
|
|
|
debug.recorded.push(`${this.namespace} ${message}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
debug.reset = function () {
|
|
|
|
debug.recorded = []
|
|
|
|
}
|
|
|
|
|
|
|
|
debug.assertContains = function (expected) {
|
|
|
|
const matches = debug.recorded.filter(message => {
|
|
|
|
return message.includes(expected)
|
|
|
|
})
|
|
|
|
if (matches.length === 0) {
|
|
|
|
throw new Error(`Expected log to contain: ${expected}`)
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 20:32:45 +00:00
|
|
|
|
|
|
|
debug.assertNotContains = function (expected) {
|
|
|
|
const matches = debug.recorded.filter(message => {
|
|
|
|
return message.includes(expected)
|
|
|
|
})
|
|
|
|
if (matches.length > 0) {
|
2018-06-16 16:26:17 +00:00
|
|
|
throw new Error(`Expected log not to contain: ${expected}, but contained at least: ${matches[0]}`)
|
2018-06-15 20:32:45 +00:00
|
|
|
}
|
|
|
|
}
|