DEVision is intended as a drop-in replacement for console.log, with the following features:
- Fast
- Isomorphic
- Elegant API
- Browser/Platform Independent
- ... did we mention, Fast?
- No run-time debug tracking in JavaScript that's browser and platform independent.
- Currently all console.log messages will run into one another & overlap
- Once done with console.logs, need to comment / uncomment may lead to errors
- No “history” of a variable’s value and “tracing” done manually
- No “diff’ing” to visually highlight the changes
- Tracing (during development) & Testing (post development) usually violate the DRY concept in work flow context
- An improved console.log replacement allowing the developer to decide (at run-time)* what will be logged based on both priority level & user-defined scope with the ability to track/snapshot variable values and test their values.
npm install devision.js
const dev = require("devision.js");
<head>
<script src="https://rawgit.com/nnZTA/DEVision.js/master/library/devision.js"></script>
<script src="https://rawgit.com/nnZTA/DEVision.js/master/library/devisionView.js"></script>
</head>
In fullfilling DEVision's primary purpose of being a drop-in replacement for console.log
it is easiest to think of it as a Log Butler that takes care of your diagnostic household. As is the Butler, it will be the gatekeeper for access to your logs. There are two primary methods (during runtime) which allow you to control your diagnostic data flow:
dev.currentPriority = 0;
dev.currentScope = ['global', 'appRunTime', 'dataIO', 'foo', ];
currentPriority
is a threshold for logging without semantic (context) info beyond the severity of the message to be logged. The implicit (automatic) default level for both dev.currentPriority
&& dev.log(...)
is 0 for all logged data. Therefore, should you use only dev.log(...)
without specifying a priority (as the second argument) you will be able to turn off all console logs by simply setting:
dev.currentPriority = 1;
... this value can be changed either at the terminal in your application, or if on the front end, in a dynamically loaded HTML interface.
currentScope
is similarly a permissive filter for your data... it will allow any data to be displayed that contains the same scope tag(s) as currently within the dev.currentScope[]
array to be displayed.
Let's look at a very simple example:
dev.log("Developer Debug Message");
dev.log("Database Connection Successful <*important status update*>", 13, 'db');
dev.log("File Write Failure <*critical alert/error*>", 42, ['error', 'devOps']);
dev.log("Database Connection Failure <*critical alert/error*>", 42, ['error', 'db', 'network']);
Given the defaults of currentPriority===0
&& currentScope===[]
the output would be:
Developer Debug Message
File Write Failure <*critical alert/error*>
Database Connection Successful <*important status update*>
Database Connection Failure <*critical alert/error*>
Given currentPriority===42
&& currentScope===[]
the output would be:
File Write Failure <*critical alert/error*>
Database Connection Failure <*critical alert/error*>
Given currentPriority===99
&& currentScope===['db']
the output would be:
Database Connection Successful <*important status update*>
Database Connection Failure <*critical alert/error*>
... noting that we can achieve the same "goal" of only seeing the "high priority" items in the second & third examples; however, the first shows only by severity (both file && db) whereas the latter only shows based upon the contextual 'db' scope.
// exp === ExpressionToBeLogged
// dev.log(exp); // example
let x = 13;
dev.log("x === " + x);
//---> x === 13
----------
// clcsv === console.log style comma delimited expressions
// note: the [] surrounding clcsv are required for this functionality
// dev.log([clcsv]); // example
let y = {someNum:13};
dev.log(["y === ", y]);
//---> y === ▶ Object { someNum: 13 }
----------
// dev.log(<exp||clcsv>, priority = 0, scope); // example
let w = 12;
let x = 13;
dev.currentPriority = x;
dev.log("w === " + w, w);
dev.log("x === " + x, x);
//---> x === 13
dev.peek(...);
dev.passThru(...);
dev.trace(...);
dev.track(...);
// ... === <exp||clcsv>, object, testCases, priority = 0, scope
```js
dev.watch(...);
"export": "node ./node_modules/devision.js/library/exportTests.js"
for multiple test cases for one objectToTest
dev.test(objToTest, [{},{},{}], dev.end);
or for only one test case for one objectToTest
dev.test(objToTest, {}, dev.end);
dev.test currently only supports these tape assertions:
equal, notEqual, deepEqual, notDeepEqual, deepLooseEqual, notDeepLooseEqual, ok, notOk, error, comment
----- inside srcFile.js:
function addTwo(num){
return num + 2;
}
module.exports = {
addTwo
}
dev.test(addTwo,
{
input: 2,
type: 'equal', // assertion type
expected: 4,
msg: [optional]
},
dev.end
);
ok : Assert that value is truthy
notOk : Assert that value is falsy
dev.test(addTwo,
{
input: 2,
type: 'ok',
msg: [optional]
},
dev.end
);
Assert that e is falsy. If e is non-falsy, use its err.message as the description message.
dev.test(addTwo,
{
type: 'error',
e: 3,
msg: 'uh oh'
},
dev.end
);
Print a message without breaking the tap output.
dev.test(addTwo,
{
type: 'comment',
msg: 'Just leaving a comment here'
},
dev.end
);
dev.test(addTwo,
[
{
input: 2,
type: 'equal',
expected: 4,
msg: 'should equal to 4'
},
{
input: 2,
type: 'notEqual',
expected: 100,
msg: 'should not equal to 100!'
},
{
type: 'error',
e: 3,
msg: 'uh oh'
},
{
input: 2,
type: 'notOk',
}
],
dev.end
);
output in exported test file:
test('TESTING addTwo', (t) => {
t.equal(srcFile.addTwo(2), 4, 'should equal to 4');
t.notEqual(srcFile.addTwo(2), 100, 'should not equal to 100!');
t.error(srcFile.addTwo(3), 'uh oh');
t.notOk(srcFile.addTwo(2));
})
Please follow the format in order for all test scripts to be exported correctly!
dev.JSs(...);
dev.JSp(...);
dev.vw(...);
If you would like to contribute, submit a pull request and update the README.md with details of changes.
This work is licensed under a Creative Commons Attribution 4.0 International License.