Skip to content

Commit

Permalink
Add object and builtin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGriffiths committed Nov 5, 2018
1 parent 01c4214 commit 1b79faa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ branches:
language: node_js
node_js:
- stable
- 10
- 9
- 8
sudo: false
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ const consoleFactory = function (options = {}) {
sOut.write(format(inspect(obj, options)));
},

pretty(obj, depth = 0) {
pretty(obj, depth = 0, color = true) {
sOut.write(format('Content: %s\n', inspect(obj, {
depth,
colors: termNG.color.basic
}).slice(0, -1).replace(/^{/, 'Object\n ').replace(/^\[/, 'Array\n ').replace(/^(\w+) {/, '$1').replace(/:/g, ' ▸').replace(/,\n/g, '\n')));
colors: color && termNG.color.basic
}).slice(0, -1).replace(/^{/, 'Object\n ').replace(/^\[/, 'Array\n ').replace(/^(\w+) {/, '$1').replace(/(\w+):/g, '$1 ▸').replace(/,\n/g, '\n')));
},

yargs(obj) {
Expand Down
6 changes: 3 additions & 3 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ const consoleFactory = function (options = {}) {
sOut.write(format(inspect(obj, options)));
},

pretty(obj, depth = 0) {
pretty(obj, depth = 0, color = true) {
sOut.write(format('Content: %s\n', inspect(obj, {
depth,
colors: termNG.color.basic
}).slice(0, -1).replace(/^{/, 'Object\n ').replace(/^\[/, 'Array\n ').replace(/^(\w+) {/, '$1').replace(/:/g, ' ▸').replace(/,\n/g, '\n')));
colors: color && termNG.color.basic
}).slice(0, -1).replace(/^{/, 'Object\n ').replace(/^\[/, 'Array\n ').replace(/^(\w+) {/, '$1').replace(/(\w+):/g, '$1 ▸').replace(/,\n/g, '\n')));
},

yargs(obj) {
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,16 @@ const consoleFactory = function (options = {}) {
* canWrite ▸ [Function]
* ...
*/
pretty(obj, depth = 0) {
pretty(obj, depth = 0, color = true) {
sOut.write(format('Content: %s\n', inspect(obj, {
depth,
colors: termNG.color.basic
colors: color && termNG.color.basic
})
.slice(0, -1)
.replace(/^{/, 'Object\n ')
.replace(/^\[/, 'Array\n ')
.replace(/^(\w+) {/, '$1')
.replace(/:/g, ' ▸')
.replace(/(\w+):/g, '$1 ▸')
.replace(/,\n/g, '\n')
))
},
Expand Down
35 changes: 35 additions & 0 deletions test/obejcts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

import stream from 'stream'
import test from 'ava'
import {createConsole} from '..'

const StreamProxy = new stream.PassThrough()
StreamProxy.setEncoding('utf8')

const testConsole = createConsole({outStream: StreamProxy})

test('Pretty print', t => {
testConsole.pretty({
test: 'Testing',
another: {
level: 'deep'
}
}, 2, false)
const result = StreamProxy.read()
t.is(result, `Content: Object\n test ▸ 'Testing', another ▸ { level ▸ 'deep' } \n`)
})

test('Object dir print', t => {
testConsole.dir({
test: 'Testing',
another: {
level: 'deep'
}
}, {
depth: 2,
colors: false
})
const result = StreamProxy.read()
t.is(result, `{ test: 'Testing', another: { level: 'deep' } }`)
})

0 comments on commit 1b79faa

Please sign in to comment.