Something went wrong. Try again.
Your trusty automation assistant in TLE Community misadventures!
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239/* global describe *//* global it *//* global beforeEach */
import chai from 'chai'import _ from 'lodash'
import { log } from '@tlecommunity/super-core'
const { expect } = chai
log.silent()
describe('log', () => { describe('#error', () => { it('be a function', () => { expect(log.error).to.be.a('function') }) })
describe('#warn', () => { it('be a function', () => { expect(log.warn).to.be.a('function') }) })
describe('#info', () => { it('be a function', () => { expect(log.info).to.be.a('function') }) })
describe('#verbose', () => { it('be a function', () => { expect(log.verbose).to.be.a('function') }) })
describe('#silly', () => { it('be a function', () => { expect(log.silly).to.be.a('function') }) })
describe('#handleConsoleOutput', () => { it(`should return ' ' for newline tokens`, () => { expect(log.handleConsoleOutput('info', '---')).to.equal(' ') })
it('should output a level and message in one string') })
describe('#prepareOutput', () => { it('should handle a normal message', () => { expect(log.prepareOutput('one two three four')).to.equal('one two three four') })
it('should handle splats', () => { expect(log.prepareOutput(['one', 'two', 'three', 'four'])).to.equal('one two three four') })
it('should handle objects', () => { expect(log.prepareOutput(['one', { two: 'three' }, 'four'])).to.equal( `one {"two":"three"} four` ) })
it('should make trailing objects look pretty', () => { expect(log.prepareOutput(['one', 'two', { three: 'four' }])).to.equal( `one two \n{\n "three": "four"\n}` ) }) })
// `log.{error, warn, info, verbose, silly}` are all the same function // bound with a different value for the log level. // Thefore, we only need to test that they're functions and do actual // tests for functionality on `log.log`. describe('#log', () => { beforeEach(() => { log.setLogLevel('silly') })
it(`should only log the message if it's valid`, () => { expect(log.log('error', 'This is an error message')).to.not.equal(false) expect(log.log('warn', 'This is a warn message')).to.not.equal(false) expect(log.log('info', 'This is an info message')).to.not.equal(false) expect(log.log('debug', 'This is a debug message')).to.not.equal(false) expect(log.log('verbose', 'This is verbose message')).to.not.equal(false) expect(log.log('silly', 'This is a silly message')).to.not.equal(false) })
it(`shouldn't log a message that's invalid`, () => { expect(log.log('something_stupid', `This shouldn't work`)).to.equal(false) expect(log.log(123456789, `This shouldn't work`)).to.equal(false) })
it('should send messages to subscribers', (done) => { let testLevel = 'info' let testMessage = 'This message is being listened for by a subscriber'
log.subscribe( _.once((level, message) => { expect(level).to.equal(testLevel) expect(message).to.equal(testMessage) done() }) )
log.log(testLevel, testMessage) }) })
describe('#newline', () => { it('should output a blank line in the console', () => { expect(log.newline()).to.equal(' ') })
it(`should output '---' to subscribers`, (done) => { log.subscribe( _.once((level, message) => { expect(level).to.equal('info') expect(message).to.equal('---') done() }) )
log.newline() }) })
describe('#isLogLevel', () => { it('should return true for valid input', () => { expect(log.isLogLevel('error')).to.equal(true) expect(log.isLogLevel('warn')).to.equal(true) expect(log.isLogLevel('info')).to.equal(true) expect(log.isLogLevel('verbose')).to.equal(true) expect(log.isLogLevel('silly')).to.equal(true) })
it('should return false for invalid input', () => { expect(log.isLogLevel(0)).to.equal(false) expect(log.isLogLevel(1)).to.equal(false) expect(log.isLogLevel(2)).to.equal(false) expect(log.isLogLevel(3)).to.equal(false) expect(log.isLogLevel(4)).to.equal(false)
expect(log.isLogLevel('something_stupid')).to.equal(false) }) })
describe('#setLogLevel', () => { it('should set the log level', () => { let newLevel = 'error' log.setLogLevel(newLevel) expect(log.logLevel).to.equal(newLevel) })
it(`should only change the log level it it's valid`, () => { let newLevel = 'something_stupid' let oldLevel = log.logLevel log.setLogLevel(newLevel) expect(log.logLevel).to.equal(oldLevel) }) })
describe('#shouldLog', () => { beforeEach(() => { log.setLogLevel('info') })
it('should return true for messages within the current log level', () => { expect(log.shouldLog('error')).to.equal(true) expect(log.shouldLog('warn')).to.equal(true) expect(log.shouldLog('info')).to.equal(true) })
it('should return false for messages outside the current log level', () => { expect(log.shouldLog('debug')).to.equal(false) expect(log.shouldLog('verbose')).to.equal(false) expect(log.shouldLog('silly')).to.equal(false) })
it('it should return false for invalid log levels', () => { expect(log.shouldLog('something_stupid')).to.equal(false) expect(log.shouldLog(123456789)).to.equal(false) }) })
describe('#colorLevel', () => { // I'm not really sure how to test this properly. :/ // TODO: come up with a way to test colorization it('should color a valid level')
it(`shouldn't color an invalid level`, () => { expect(log.colorLevel('something_stupid')).to.equal('something_stupid') expect(log.colorLevel(123456789)).to.equal(123456789) }) })
describe('#subscribe', () => { beforeEach(() => { log.unsubscribeAll() })
it('should add a callback to the subscribers array', () => { log.subscribe(_.noop) expect(log.subscribers.length).to.equal(1) }) })
describe('#unsubscribeAll', () => { beforeEach(() => { log.subscribe(_.noop) })
it('should empty the subscribers array', () => { log.unsubscribeAll() expect(log.subscribers.length).to.equal(0) }) })
describe('#broadcast', () => { let testLevel = 'info' let testMessage = 'hellow i am a test'
it('should broadcast a message to subscribers', () => { log.subscribe( _.once((level, message) => { expect(level).to.equal(testLevel) expect(message).to.equal(testMessage) }) )
log.log(testLevel, testMessage) }) })})