Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guigrpa committed Jun 27, 2016
1 parent e7f7664 commit c3c56b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/example/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ someInfo =
foo: undefined
bar: null
values: [1, 2]
shortBuffer: Buffer.from([0, 1, 2, 3])
longBuffer: Buffer.from(x for x in [0...1000])
someInfo.nested.configOptions.mainInfo = someInfo
mainStory.debug 'server', "Example info:",
attach: someInfo
Expand Down
7 changes: 4 additions & 3 deletions src/gral/treeLines.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _ = require '../vendor/lodash'
{CIRCULAR_REF} = require './serialize'

WRAPPER_KEY = '__wrapper__'
BUFFER_EXPLICIT_LIMIT = 40

_tree = (node, options, prefix, stack) ->
out = []
Expand All @@ -25,9 +26,9 @@ _tree = (node, options, prefix, stack) ->
else if _.isDate(val)
out.push "#{finalPrefix}#{chalk.magenta.bold val.toISOString()}"
else if val instanceof Buffer
str = val.slice(0, 50).toString('hex').toUpperCase().match(/(..)/g).join(' ')
if val.length > 50 then str += '...'
str = "Buffer [#{val.length}]: #{str}"
str = val.slice(0, BUFFER_EXPLICIT_LIMIT).toString('hex').toUpperCase().match(/(..)/g).join(' ')
if val.length > BUFFER_EXPLICIT_LIMIT then str += '...'
str = "Buffer [#{val.length}]: #{str}"
out.push "#{finalPrefix}#{chalk.magenta str}"
else if _.isObject(val) and Object.keys(val).length is 0
out.push "#{finalPrefix}#{chalk.bold '{}'}"
Expand Down
14 changes: 14 additions & 0 deletions test/lib/03-treeLines.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ describe 'treeLines', ->
expect(lines[1]).to.contain 'message'
expect(lines[2]).to.contain 'stack'

it 'should handle buffers (top level)', ->
lines = treeLines Buffer.from [0, 1, 2]
expect(lines).to.have.length 1
expect(lines[0].indexOf('Buffer [3]')).to.be.at.least 0

it 'should handle buffers (nested)', ->
lines = treeLines
a: Buffer.from [0, 1, 2]
b: Buffer.from(x for x in [0...1000])
expect(lines).to.have.length 2
expect(lines[0].indexOf('Buffer [3]')).to.be.at.least 0
expect(lines[1].indexOf('Buffer [1000]')).to.be.at.least 0
expect(lines[1]).to.contain '...'

it 'should provide simple console output', ->
sinon.spy console, 'log'
treeLines.log {a: 3}
Expand Down

0 comments on commit c3c56b3

Please sign in to comment.