console-dot
Advanced tools
Comparing version 0.1.2 to 0.2.0
"use strict"; | ||
var __moduleName = "lib_index"; | ||
function ConsoleDot() { | ||
var delimeter = arguments[0] !== (void 0) ? arguments[0] : 'console.callback --------'; | ||
var message = arguments[1] !== (void 0) ? arguments[1] : 'callback fired'; | ||
var showArgsMessage = arguments[2] !== (void 0) ? arguments[2] : 'showing arguments received --------'; | ||
if (!(this instanceof ConsoleDot)) { | ||
return new ConsoleDot(); | ||
return new ConsoleDot(delimeter, message, showArgsMessage); | ||
} | ||
ConsoleDot.prototype.initialize(delimeter, message, showArgsMessage); | ||
} | ||
; | ||
ConsoleDot.__proto__ = console.__proto__; | ||
ConsoleDot.__proto__.constants = Object.freeze({ | ||
DELIMETER: 'console.callback --------', | ||
MESSAGE: 'callback fired', | ||
SHOW_ARGS_MESSAGE: 'showing arguments received --------' | ||
}); | ||
ConsoleDot.prototype.initialize = function(delimeter, message, showArgsMessage) { | ||
ConsoleDot.__proto__.constants = Object.freeze({ | ||
DELIMETER: delimeter, | ||
MESSAGE: message, | ||
SHOW_ARGS_MESSAGE: showArgsMessage | ||
}); | ||
}; | ||
ConsoleDot.__proto__.callback = function consoleCallback() { | ||
@@ -16,0 +22,0 @@ var showArgs = arguments[0] !== (void 0) ? arguments[0] : true; |
function ConsoleDot () { | ||
function ConsoleDot (delimeter = 'console.callback --------', message = 'callback fired', showArgsMessage = 'showing arguments received --------') { | ||
if (!(this instanceof ConsoleDot)) { | ||
return new ConsoleDot(); | ||
return new ConsoleDot(delimeter, message, showArgsMessage); | ||
} | ||
ConsoleDot.prototype.initialize(delimeter, message, showArgsMessage); | ||
}; | ||
@@ -10,7 +12,10 @@ | ||
ConsoleDot.__proto__.constants = Object.freeze({ | ||
DELIMETER: 'console.callback --------', | ||
MESSAGE: 'callback fired', | ||
SHOW_ARGS_MESSAGE: 'showing arguments received --------' | ||
}); | ||
// I have questions about this. | ||
ConsoleDot.prototype.initialize = function (delimeter, message, showArgsMessage) { | ||
ConsoleDot.__proto__.constants = Object.freeze({ | ||
DELIMETER: delimeter, | ||
MESSAGE: message, | ||
SHOW_ARGS_MESSAGE: showArgsMessage | ||
}); | ||
}; | ||
@@ -17,0 +22,0 @@ // Provides a callback style curry function that accepts `showArgs` and `...logMessage` |
@@ -26,3 +26,3 @@ { | ||
}, | ||
"version": "0.1.2" | ||
"version": "0.2.0" | ||
} |
@@ -42,2 +42,4 @@ # ConsoleDot | ||
## v0.2.0 | ||
Much, much better functional test coverage for default & desired behaviors. | ||
@@ -44,0 +46,0 @@ ## v0.1.2 |
var _ = require('lodash'), | ||
ConsoleDot = require('../.'), | ||
Should = require('should'); | ||
Should = require('should'), | ||
Util = require('util'); | ||
describe('ConsoleDot Test Suite', function () { | ||
var originalConsole = console; | ||
before(function initialize() { | ||
@@ -13,9 +16,32 @@ console = ConsoleDot(); | ||
describe('#callback()', function () { | ||
it('should expose a .callback() function', function (passed) { | ||
Should(console).have.property('callback'); | ||
Should(console.callback).be.a.Function; | ||
passed(); | ||
describe('Definition & API', function () { | ||
it('should expose a .callback() function', function (passed) { | ||
Should(console).have.property('callback'); | ||
Should(console.callback).be.a.Function; | ||
passed(); | ||
}); | ||
it('should properly define constants', function (passed) { | ||
Should(console).have.property('constants'); | ||
passed(); | ||
}); | ||
// trying to assert that I didn't totally fuckup the original console by magic | ||
it('should prototype similarly to the original `console` without breaking it', function (passed) { | ||
console.__proto__.should.eql(originalConsole.__proto__); | ||
console.should.have.property('log').Function.eql(originalConsole.log); | ||
console.should.have.property('info').Function.eql(originalConsole.info); | ||
console.should.have.property('warn').Function.eql(originalConsole.warn); | ||
console.should.have.property('error').Function.eql(originalConsole.error); | ||
console.should.have.property('dir').Function.eql(originalConsole.dir); | ||
console.should.have.property('time').Function.eql(originalConsole.time); | ||
console.should.have.property('timeEnd').Function.eql(originalConsole.timeEnd); | ||
console.should.have.property('trace').Function.eql(originalConsole.trace); | ||
console.should.have.property('assert').Function.eql(originalConsole.assert); | ||
passed(); | ||
}); | ||
}); | ||
describe('should produce desired output', function () { | ||
describe('Standard API & Output Behavior', function () { | ||
// http://stackoverflow.com/a/9624028 | ||
@@ -40,5 +66,2 @@ var hook_stream = function(_stream, fn) { | ||
logs = []; | ||
}); | ||
before(function () { | ||
unhook_stdout = hook_stream(process.stdout, function(string, encoding, fd) { | ||
@@ -49,6 +72,2 @@ logs.push(string); | ||
after(function () { | ||
unhook_stdout(); | ||
}); | ||
it('should fire with the defaults', function (passed) { | ||
@@ -58,4 +77,2 @@ var cb = console.callback(); | ||
cb(); | ||
unhook_stdout(); | ||
logs = trim_newline(logs); | ||
@@ -65,21 +82,71 @@ | ||
logs.should.have.a.length(5); | ||
logs[0].should.eql(ConsoleDot.constants.DELIMETER); | ||
logs[1].should.eql(ConsoleDot.constants.MESSAGE); | ||
logs[2].should.eql(ConsoleDot.constants.SHOW_ARGS_MESSAGE); | ||
logs[0].should.eql(console.constants.DELIMETER); | ||
logs[1].should.eql(console.constants.MESSAGE); | ||
logs[2].should.eql(console.constants.SHOW_ARGS_MESSAGE); | ||
logs[3].should.eql(''); | ||
logs[4].should.eql(ConsoleDot.constants.DELIMETER); | ||
logs[4].should.eql(console.constants.DELIMETER); | ||
unhook_stdout(); | ||
passed(); | ||
}); | ||
it('2 should fire with the defaults', function (passed) { | ||
var cb = console.callback(); | ||
it('should log arguments passed to the callback', function (passed) { | ||
var args = { key: 'value' }, | ||
cb = console.callback(true), | ||
argsOutput; | ||
cb(); | ||
cb(args); | ||
logs = trim_newline(logs); | ||
argsOutput = eval('(' + logs[3] + ')'); | ||
logs.should.have.a.length(5); | ||
argsOutput.should.eql(args); | ||
unhook_stdout(); | ||
passed(); | ||
}); | ||
it('should not log arguments when turned off', function (passed) { | ||
var args = { key: 'value' }, | ||
cb = console.callback(false); | ||
cb(args); | ||
logs.should.have.length(3); | ||
unhook_stdout(); | ||
passed(); | ||
}); | ||
it('should log a given simple message', function (passed) { | ||
var message = 'Well then, I see.', | ||
cb = console.callback(false, message); | ||
cb('lolz'); | ||
logs = trim_newline(logs); | ||
logs.should.have.a.length(3); | ||
logs[1].should.eql(message); | ||
unhook_stdout(); | ||
passed(); | ||
}); | ||
it('should log a given complex message', function (passed) { | ||
var message = 'Well then, I see, %s @ %s', | ||
name = 'Stephen', | ||
date = new Date(), | ||
cb = console.callback(false, message, name, date); | ||
cb('lolz'); | ||
logs = trim_newline(logs); | ||
logs.should.have.a.length(3); | ||
logs[1].should.eql(Util.format(message, name, date)); | ||
unhook_stdout(); | ||
passed(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11877
223
50
1