You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
thumbsup/test/log.js

40 lines
1008 B
JavaScript

const util = require('node:util')
const debug = require('debug')
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}`)
}
}
debug.assertNotContains = function (expected) {
const matches = debug.recorded.filter(message => {
return message.includes(expected)
})
if (matches.length > 0) {
throw new Error(`Expected log not to contain: ${expected}, but contained at least: ${matches[0]}`)
}
}