added unit testing, and started implementing unit tests...phew

This commit is contained in:
Josh Burman
2019-03-12 22:28:02 -04:00
parent 74aad4a957
commit e8c2539f1b
3489 changed files with 464813 additions and 88 deletions

5
node_modules/diagnostics/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,5 @@
language: node_js
node_js:
- "9"
- "8"
- "6"

20
node_modules/diagnostics/LICENSE.md generated vendored Normal file
View File

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2015 Arnout Kazemier, Martijn Swaagman, the Contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

135
node_modules/diagnostics/README.md generated vendored Normal file
View File

@ -0,0 +1,135 @@
# Diagnostics
[![Build Status](https://travis-ci.org/bigpipe/diagnostics.svg?branch=master)](https://travis-ci.org/bigpipe/diagnostics)
Diagnostics is a small debugging library which allows you to output your debug
logs by setting an environment variable. The library works for server-side and
client-size applications so it's great for writing isomorphic JavaScript.
The debug output can be triggered using environment variables on the server and
using localStorage, hashtags and window.name on the browser. If the debug output
is not enabled this module will result in an empty function causing the
JavaScript compiler engines to remove it completely from your code so there is
absolutely no performance overhead or excuses left to not use logging in your
code!
## Installation
The module is released in the public npm registry and can easily be installed by
running.
```
npm install --save diagnostics
```
For client-side/front-end facing application we assume that you're using
`browserify` as your build tool as the client code is bundled as the
`browser.js` file in the root of this repository.
## Usage
When you require the module it returns a function that expect a name or prefix
for the debug messages. This prefix is what you use to enable specific debug
messages.
The exported function of the module accepts 2 arguments:
1. `name` The namespace of the debug logger.
2. `options` These options can only be applied to the server, not client code:
- `colors`: Enable or disable colors. Defaults to true if your stdout is a tty.
- `stream`: The stream instance we should write our logs to. We default to
`process.stdout` (unless you change the default using the `.to` method).
```js
var debug = require('diagnostics')('foo');
debug('hello world %d', 12);
```
In the example above you can see that we've created a new diagnostics function
called debug. It's name is set to `foo`. So when we run this in Node.js using:
```
node index.js
```
We will see nothing in the console as the log messages are disabled by default.
But when set the `DEBUG` or `DIAGNOSTICS` environment variables to the name of
the debug function it will show up:
```
DIAGNOSTICS=foo node index.js
hello world 12
```
You can enable or disable specific diagnostic instances in the ENV variables by
separating them using a space or comma:
```
DEBUG=foo,-bar,primus:*
```
In the example above you also see an example of a wild card `*`. This ensures
that anything after it or before it will be allowed.
To make it easier to see where the log messages are coming from they are
colored automatically based on the namespace you provide them. The deeper the
namespace, the lighter name will be toned as seen in the following output.
![output](output.PNG)
## Browser
The usage for browser is exactly the same as for node. You require the
`diagnostics` method and supply it with a name argument. The big difference is
that no longer can use environment variables as these only work on the server.
So to go around that you can use:
- **hashtag** The hashtag will be parsed using query string decoding. So if you
have an hash `#debug=foo` it will trigger all `foo` lines to be dumped to your
browser console.
- **localStorage** We will search for a query string in either the `env` or
`debug` key of `localStorage`. We again assume that the value has query string
encode value which contains either `debug` or `diagnostics`.
`localStorage.env = 'diagnostics=foo'`.
- **window.name** As `localStorage` is not available in all browsers, we provide
a fallback to `window.name` which can contain the same values as the
`localStorage`'s env/debug keys.
Unlike the server, the output of the browser is not colored. The reason for this
that it would take a considerable amount of code. Which is not worth the benefit
as you usually want your front-end code to be as small as possible.
#### Multiple streams
> Please note that this feature is server-side only as in the browser we can only
> output to the console
The beauty of this logger is that it allows a custom stream where you can write
the data to. So you can just log it all to a separate server, database and what
not. But we don't just allow one stream we allow multiple streams so you might
want to log to disk AND just output it in your terminal. The only thing you need
to do is either use:
```js
require('diagnostics').to([
stream1,
stream2
]);
```
To set multiple streams as the default streams or supply an array for the logger
it self:
```js
var debug = require('diagnostics')('example', { stream: [
stream1,
stream2
]});
debug('foo');
```
## License
[MIT](LICENSE.md)

35
node_modules/diagnostics/browser.js generated vendored Normal file
View File

@ -0,0 +1,35 @@
'use strict';
var enabled = require('enabled');
/**
* Bare minimum browser version of diagnostics. It doesn't need fancy pancy
* detection algorithms. The code is only enabled when *you* enable it for
* debugging purposes.
*
* @param {String} name Namespace of the diagnostics instance.
* @returns {Function} The logger.
* @api public
*/
module.exports = function factory(name) {
if (!enabled(name)) return function diagnopes() {};
return function diagnostics() {
var args = Array.prototype.slice.call(arguments, 0);
//
// We cannot push a value as first argument of the argument array as
// console's formatting %s, %d only works on the first argument it receives.
// So in order to prepend our namespace we need to override and prefix the
// first argument.
//
args[0] = name +': '+ args[0];
//
// So yea. IE8 doesn't have an apply so we need a work around to puke the
// arguments in place.
//
try { Function.prototype.apply.call(console.log, console, args); }
catch (e) {}
};
};

2051
node_modules/diagnostics/dist/diagnostics.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

49
node_modules/diagnostics/example.js generated vendored Normal file
View File

@ -0,0 +1,49 @@
'use strict';
//
// Please run this example with the correct environment flag `DEBUG=*` or
// `DEBUG=big*` or what ever. For example:
//
// ```
// DEBUG=* node example.js
// ```
//
var log;
//
// Ignore this piece of code, it's merely here so we can use the `diagnostics`
// module if installed or just the index file of this repository which makes it
// easier to test. Normally you would just do:
//
// ```js
// var log = require('diagnostics');
// ```
//
// And everything will be find and dandy.
//
try { log = require('diagnostics'); }
catch (e) { log = require('./'); }
//
// In this example we're going to output a bunch on logs which are namespace.
// This gives a visual demonstration.
//
[
log('bigpipe'),
log('bigpipe:pagelet'),
log('bigpipe:page'),
log('bigpipe:page:rendering'),
log('bigpipe:primus:event'),
log('primus'),
log('primus:event'),
log('lexer'),
log('megatron'),
log('cows:moo'),
log('moo:moo'),
log('moo'),
log('helloworld'),
log('helloworld:bar')
].forEach(function (log) {
log('foo');
});

106
node_modules/diagnostics/index.js generated vendored Normal file
View File

@ -0,0 +1,106 @@
'use strict';
var colorspace = require('colorspace')
, enabled = require('enabled')
, kuler = require('kuler')
, util = require('util');
/**
* Check if the terminal we're using allows the use of colors.
*
* @type {Boolean}
* @private
*/
var tty = require('tty').isatty(1);
/**
* The default stream instance we should be writing against.
*
* @type {Stream}
* @public
*/
var stream = process.stdout;
/**
* A simple environment based logger.
*
* Options:
*
* - colors: Force the use of colors or forcefully disable them. If this option
* is not supplied the colors will be based on your terminal.
* - stream: The Stream instance we should write our logs to, defaults to
* process.stdout but can be anything you like.
*
* @param {String} name The namespace of your log function.
* @param {Object} options Logger configuration.
* @returns {Function} Configured logging method.
* @api public
*/
function factory(name, options) {
if (!enabled(name)) return function diagnopes() {};
options = options || {};
options.colors = 'colors' in options ? options.colors : tty;
options.ansi = options.colors ? kuler(name, colorspace(name)) : name;
options.stream = options.stream || stream;
//
// Allow multiple streams, so make sure it's an array which makes iteration
// easier.
//
if (!Array.isArray(options.stream)) {
options.stream = [options.stream];
}
//
// The actual debug function which does the logging magic.
//
return function debug(line) {
//
// Better formatting for error instances.
//
if (line instanceof Error) line = line.stack || line.message || line;
line = [
//
// Add the colorized namespace.
//
options.ansi,
//
// The total time we took to execute the next debug statement.
//
' ',
line
].join('');
//
// Use util.format so we can follow the same API as console.log.
//
line = util.format.apply(this, [line].concat(
Array.prototype.slice.call(arguments, 1)
)) + '\n';
options.stream.forEach(function each(stream) {
stream.write(line);
});
};
}
/**
* Override the "default" stream that we write to. This allows you to globally
* configure the steams.
*
* @param {Stream} output
* @returns {function} Factory
* @api private
*/
factory.to = function to(output) {
stream = output;
return factory;
};
//
// Expose the module.
//
module.exports = factory;

BIN
node_modules/diagnostics/output.PNG generated vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

82
node_modules/diagnostics/package.json generated vendored Normal file
View File

@ -0,0 +1,82 @@
{
"_from": "diagnostics@^1.1.1",
"_id": "diagnostics@1.1.1",
"_inBundle": false,
"_integrity": "sha512-8wn1PmdunLJ9Tqbx+Fx/ZEuHfJf4NKSN2ZBj7SJC/OWRWha843+WsTjqMe1B5E3p28jqBlp+mJ2fPVxPyNgYKQ==",
"_location": "/diagnostics",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "diagnostics@^1.1.1",
"name": "diagnostics",
"escapedName": "diagnostics",
"rawSpec": "^1.1.1",
"saveSpec": null,
"fetchSpec": "^1.1.1"
},
"_requiredBy": [
"/winston"
],
"_resolved": "https://registry.npmjs.org/diagnostics/-/diagnostics-1.1.1.tgz",
"_shasum": "cab6ac33df70c9d9a727490ae43ac995a769b22a",
"_spec": "diagnostics@^1.1.1",
"_where": "/Users/josh.burman/Projects/braid/node_modules/winston",
"author": {
"name": "Arnout Kazemier"
},
"browser": "./browser.js",
"bugs": {
"url": "https://github.com/bigpipe/diagnostics/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Martijn Swaagman",
"url": "https://github.com/swaagie"
},
{
"name": "Jarrett Cruger",
"url": "https://github.com/jcrugzz"
},
{
"name": "Sevastos",
"url": "https://github.com/sevastos"
}
],
"dependencies": {
"colorspace": "1.1.x",
"enabled": "1.0.x",
"kuler": "1.0.x"
},
"deprecated": false,
"description": "Tools for debugging your node.js modules and event loop",
"devDependencies": {
"assume": "2.1.x",
"mocha": "5.2.x",
"pre-commit": "1.2.x"
},
"homepage": "https://github.com/bigpipe/diagnostics",
"keywords": [
"debug",
"debugger",
"debugging",
"diagnostic",
"diagnostics",
"event",
"loop",
"metrics",
"stats"
],
"license": "MIT",
"main": "index.js",
"name": "diagnostics",
"repository": {
"type": "git",
"url": "git://github.com/bigpipe/diagnostics.git"
},
"scripts": {
"test": "mocha --reporter spec --ui bdd test.js"
},
"version": "1.1.1"
}

50
node_modules/diagnostics/test.js generated vendored Normal file
View File

@ -0,0 +1,50 @@
describe('diagnostics', function () {
'use strict';
var assume = require('assume')
, debug = require('./');
beforeEach(function () {
process.env.DEBUG = '';
process.env.DIAGNOSTICS = '';
});
it('is exposed as function', function () {
assume(debug).to.be.a('function');
});
it('stringifies objects', function (next) {
process.env.DEBUG = 'test';
debug.to({
write: function write(line) {
assume(line).to.contain('test');
assume(line).to.contain('I will be readable { json: 1 }');
debug.to(process.stdout);
next();
}
});
debug('test')('I will be readable', { json: 1 });
});
describe('.to', function () {
it('globally overrides the stream', function (next) {
process.env.DEBUG = 'foo';
debug.to({
write: function write(line) {
assume(line).to.contain('foo');
assume(line).to.contain('bar');
debug.to(process.stdout);
next();
}
});
var log = debug('foo');
log('bar');
});
});
});