我正在尝试提高此文件的测试覆盖率
'use strict'
/**
* Returns the logging options we're using
*
* @param {String} name Name of the logger. Should be service name. e.g. ciitizen-file-service
* @returns {Object} The logging options we're using
* @private
*/
function getLoggerOptions(name) {
return {
name: name,
streams: [
{
level: 'info',
stream: stdOutStream()
}, {
level: 'error',
stream: stdErrStream()
}
, {
level: 'debug',
stream: stdOutStream()
},
{
level: 'warn',
stream: stdOutStream()
},
{
level: 'fatal',
stream: stdErrStream()
}
]
}
}
/**
* Creates a stream that writes to stdout
*
* @param {Object} info The log info
* @returns {Object} An object which logs to stdout
* @private
*/
function stdOutStream() {
return {
write: log => {
// Change log level number to name and write it out
log.level = bunyan.nameFromLevel[log.level]
process.stdout.write(JSON.stringify(log) + '\n')
}
}
}
/**
* Creates a stream that writes to stderr
*
* @param {Object} info The log info
* @returns {Object} An object which logs to stderr
* @private
*/
function stdErrStream() {
return {
write: log => {
// Change log level number to name and write it out
log.level = bunyan.nameFromLevel[log.level]
process.stderr.write(JSON.stringify(log) + '\n')
}
}
}
module.exports = { getLoggerOptions }
我目前有这个测试
'use strict'
const expect = require('chai').expect
const { getLoggerOptions } = require('../src/helpers')
describe.only('#getLoggerOptions', () => {
it('should return the logger options', () => {
expect(getLoggerOptions('test')).to.be.an('object')
})
})
我如何编写测试来覆盖此代码?