chore(tests): capture all logs during the tests so they don’t pollute the output + can be asserted on

pull/118/head
Romain 6 years ago
parent 3fa8867757
commit 3fd0ee9ba3

@ -0,0 +1,30 @@
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}`)
}
}

@ -1,2 +1,3 @@
--recursive
--require test/helpers.js
--require test/log.js

Loading…
Cancel
Save