Skip to content

Commit

Permalink
test and quiet interaction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Sep 2, 2019
1 parent 9bd79b2 commit 4ec81b6
Show file tree
Hide file tree
Showing 9 changed files with 793 additions and 381 deletions.
63 changes: 41 additions & 22 deletions lib/api.js
Expand Up @@ -199,12 +199,12 @@ exports.delegate = function(fixedargs, fixedmeta) {
delegate.did =
(delegate.did ? delegate.did + '/' : '') + self.private$.didnid()


delegate.log = function log() { return root.log.apply(delegate, arguments)}
Object.assign(delegate.log,root.log)
delegate.log = function log() {
return root.log.apply(delegate, arguments)
}
Object.assign(delegate.log, root.log)
delegate.log.self = () => delegate


var strdesc
delegate.toString = function toString() {
if (strdesc) return strdesc
Expand Down Expand Up @@ -285,17 +285,27 @@ exports.export = function(key) {
return exportval
}

// TODO: logging needs to be able to support this without reload awkwardness!
// TODO: boolean to turn on/off
exports.quiet = function() {
this.options({
exports.quiet = function(flags) {
flags = flags || {}

var quiet_opts = {
test: false,
quiet: true,
log: 'warn'
})
log: 'none',
reload$: true
}

this.private$.logging.build_log(this)

return this
var opts = this.options(quiet_opts)

// An override from env or args is possible.
// Only flip to test mode if called from test() method
if (opts.test && 'test' !== flags.from) {
return this.test()
} else {
this.private$.logging.build_log(this)

return this
}
}

exports.test = function(errhandler, logspec) {
Expand All @@ -313,23 +323,32 @@ exports.test = function(errhandler, logspec) {
errhandler = null
}

logspec = true === logspec || 'true' === logspec ? 'test' : logspec

var test_opts = {
errhandler: null == errhandler ? null : errhandler,
test: true,
log: logspec || 'test',
quiet: false,
reload$: true,
log: logspec || 'test'
}

this.options(test_opts)
var set_opts = this.options(test_opts)

// An override from env or args is possible.
if (set_opts.quiet) {
return this.quiet({ from: 'test' })
} else {
this.private$.logging.build_log(this)

this.private$.logging.build_log(this)
// Manually set logger to test_logger (avoids infecting options structure),
// unless there was an external logger defined by the options
if (!this.private$.logger.from_options$) {
this.root.private$.logger = this.private$.logging.test_logger
}

// Manually set logger to test_logger (avoids infecting options structure),
// unless there was an external logger defined by the options
if(!this.private$.logger.from_options$) {
this.root.private$.logger = this.private$.logging.test_logger
return this
}

return this
}

// use('pluginname') - built-in, or provide calling code 'require' as seneca opt
Expand Down

0 comments on commit 4ec81b6

Please sign in to comment.