Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Apr 30, 2016
1 parent ac1a16d commit 91cbdc9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
32 changes: 10 additions & 22 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
'use strict'

Acho = require '..'
util = require './util'
should = require 'should'

randomInterval = (min, max) ->
Math.floor(Math.random()*(max-min+1)+min)

printLogs = (acho) ->
levels = Object.keys(acho.types)
levels.forEach (level) -> acho[level](level + ' message')

createFakeTransport = ->
store = []
transport = ->
console.log.apply(console, arguments)
store.push.apply(store, arguments)
transport.store = store
transport

describe 'Acho ::', ->

beforeEach ->
opts =
color: true
outputType: (type) -> "[#{type}] » "
transport: createFakeTransport()
transport: util.createFakeTransport()
@acho = Acho opts

describe 'initialization', ->
Expand All @@ -37,7 +25,7 @@ describe 'Acho ::', ->

it 'passing a initial store state', ->
instance = Acho
transport: createFakeTransport()
transport: util.createFakeTransport()
messages:
info: ['info message']

Expand Down Expand Up @@ -87,26 +75,26 @@ describe 'Acho ::', ->
describe 'customization', ->
it 'default skin', ->
instance = Acho()
printLogs instance
util.printLogs instance
(instance.keyword?).should.be.false

it 'specifying a keyword', ->
instance = Acho color: true, keyword: 'acho'
printLogs instance
util.printLogs instance
instance.keyword.should.be.equal 'acho'

it 'specifying a special "symbol" keyword', ->
instance = Acho color: true, keyword: 'symbol'
printLogs instance
util.printLogs instance
instance.keyword.should.be.equal 'symbol'

it 'enabling diff between logs', (done) ->
acho = Acho color: true, diff: true, timestamp: true, align: false
printWarn = -> acho.warn 'hello world'
printErr = -> acho.error 'oh noes!'

warn = setInterval(printWarn, randomInterval(1000, 2000))
err = setInterval(printErr, randomInterval(2000, 2500))
warn = setInterval(printWarn, util.randomInterval(1000, 2000))
err = setInterval(printErr, util.randomInterval(2000, 2500))

setTimeout(->
clearInterval warn
Expand Down
21 changes: 21 additions & 0 deletions test/test.skin.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

Acho = require '..'
util = require './util'
skinCli = require 'acho-skin-cli'

inlineSkin =
types:
pokemon:
level : 4
color : 'blue'

describe 'Acho :: skin', ->
it 'load an skin', ->
AchoCLI = Acho.skin(skinCli)

instance = AchoCLI
uppercase: true

levels = Object.keys(instance.types)
levels.should.be.eql ['debug', 'info', 'success', 'warn', 'error']
18 changes: 18 additions & 0 deletions test/util.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

module.exports =
randomInterval: (min, max) ->
Math.floor(Math.random()*(max-min+1)+min)

printLogs: (acho) ->
levels = Object.keys(acho.types)
levels.forEach (level) -> acho[level](level + ' message')

createFakeTransport: ->
store = []
transport = ->
console.log.apply(console, arguments)
store.push.apply(store, arguments)
transport.store = store
transport

0 comments on commit 91cbdc9

Please sign in to comment.