Skip to content

Commit

Permalink
Fix Object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGriffiths committed Nov 5, 2018
1 parent e77cc68 commit 01c4214
Show file tree
Hide file tree
Showing 8 changed files with 912 additions and 1,071 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var util = _interopDefault(require('util'));
var _console = _interopDefault(require('console'));
var console = require('console');
var termNG = _interopDefault(require('term-ng'));
var chalk = _interopDefault(require('chalk'));
var sparkles = _interopDefault(require('sparkles'));
Expand Down Expand Up @@ -52,7 +52,7 @@ const consoleFactory = function (options = {}) {

const prefixFormatter = (pfix => pfix ? () => `[${pfix}] ` : () => '')(prefix);

return Object.assign(Object.create(_console.Console), {
return Object.assign(new console.Console(sOut, sErr), {
_stdout: sOut,
_stderr: sErr,
threshold: verbosity ? verbosity : 3,
Expand Down Expand Up @@ -219,7 +219,7 @@ const consoleFactory = function (options = {}) {
};


function console(options) {
function console$1(options) {
return consoleFactory(options);
}

Expand All @@ -229,6 +229,6 @@ function createConsole(options) {

const getVersion = level => metadata.version(level);

exports.console = console;
exports.console = console$1;
exports.createConsole = createConsole;
exports.getVersion = getVersion;
4 changes: 2 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import util from 'util';
import _console from 'console';
import { Console } from 'console';
import termNG from 'term-ng';
import chalk from 'chalk';
import sparkles from 'sparkles';
Expand Down Expand Up @@ -46,7 +46,7 @@ const consoleFactory = function (options = {}) {

const prefixFormatter = (pfix => pfix ? () => `[${pfix}] ` : () => '')(prefix);

return Object.assign(Object.create(_console.Console), {
return Object.assign(new Console(sOut, sErr), {
_stdout: sOut,
_stderr: sErr,
threshold: verbosity ? verbosity : 3,
Expand Down
1,913 changes: 870 additions & 1,043 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@
},
"homepage": "https://github.com/MarkGriffiths/verbosity#readme",
"dependencies": {
"@thebespokepixel/meta": "^0.2.2",
"@thebespokepixel/time": "^0.4.0",
"@thebespokepixel/meta": "^0.2.3",
"@thebespokepixel/time": "^0.4.1",
"chalk": "^2.4.1",
"sparkles": "^1.0.1",
"term-ng": "^0.8.1"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.51",
"@babel/preset-env": "^7.0.0-beta.51",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"ava": "^0.25.0",
"documentation": "^8.0.0",
"documentation": "^8.1.2",
"documentation-theme-bespoke": "^0.4.3",
"gulp": "^4.0.0",
"gulp-better-rollup": "^3.2.1",
"gulp-rename": "^1.3.0",
"gulp-better-rollup": "^3.4.0",
"gulp-rename": "^1.4.0",
"gulp-strip-comments": "^2.5.2",
"nyc": "^12.0.2",
"rollup-plugin-babel": "^4.0.0-beta.5",
"xo": "^0.21.1"
"rollup-plugin-babel": "^4.0.3",
"xo": "^0.23.0"
},
"xo": {
"semicolon": false,
Expand All @@ -80,7 +80,6 @@
"test/*.js"
]
},
"buildNumber": 2,
"badges": {
"github": "MarkGriffiths",
"npm": "thebespokepixel",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import util from 'util'

import _console from 'console'
import {Console} from 'console'

import termNG from 'term-ng'
import chalk from 'chalk'
Expand Down Expand Up @@ -64,7 +64,7 @@ const consoleFactory = function (options = {}) {
() => ''
)(prefix)

return Object.assign(Object.create(_console.Console), {
return Object.assign(new Console(sOut, sErr), {
_stdout: sOut,
_stderr: sErr,
threshold: verbosity ? verbosity : 3,
Expand Down
4 changes: 2 additions & 2 deletions test/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ StreamProxy.setEncoding('utf8')

const testConsole = createConsole({outStream: StreamProxy})

test(`Multiple arguments`, t => {
test('Multiple arguments', t => {
testConsole.log('this', 'has', 'many', 'arguments')
const result = StreamProxy.read()
t.is(result, 'this has many arguments\n')
})

test(`Printf-like arguments`, t => {
test('Printf-like arguments', t => {
testConsole.log('this %s %s', 'has', 'printf', 'like', 'arguments')
const result = StreamProxy.read()
t.is(result, 'this has printf like arguments\n')
Expand Down
21 changes: 21 additions & 0 deletions test/builtin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'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('Default count', t => {
testConsole.count()
testConsole.count()
testConsole.count()
const result = StreamProxy.read()
t.is(result, `default: 1
default: 2
default: 3
`)
})
10 changes: 2 additions & 8 deletions test/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ import test from 'ava'
import {createConsole, getVersion} from '..'
import pkg from '../package'

const expectedVersion = ((pkg.buildNumber === 0) && pkg.version) || `${pkg.version}${pkg.buildNumber}`

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

test(`Module version is '${pkg.version}'.`, t => {
t.is(`${expectedVersion}`, getVersion())
t.is(`${pkg.version}`, getVersion())
})

test(`Module long version is '${pkg.name} v${pkg.version}'.`, t => {
t.is(`${pkg.name} v${expectedVersion}`, getVersion(2))
t.is(`${pkg.name} v${pkg.version}`, getVersion(2))
})

const testConsole = createConsole({outStream: StreamProxy})

test('Verbosity Console‘s prototype inherits from console', t => {
t.true(testConsole.prototype === Object.getPrototypeOf(console))
})

test('Default level is 3 (log)', t => {
t.is(testConsole.verbosity(), 3)
})
Expand Down

0 comments on commit 01c4214

Please sign in to comment.