Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,4 @@
**/__mocks__/**
**/__tests__/**
src
yarn.lock

View File

@@ -0,0 +1,134 @@
# pretty-format
> Stringify any JavaScript value.
- Supports [all built-in JavaScript types](#type-support)
- [Blazingly fast](https://gist.github.com/thejameskyle/2b04ffe4941aafa8f970de077843a8fd) (similar performance to v8's `JSON.stringify` and significantly faster than Node's `util.format`)
- Plugin system for extending with custom types (i.e. [`ReactTestComponent`](#reacttestcomponent-plugin))
## Installation
```sh
$ yarn add pretty-format
```
## Usage
```js
const prettyFormat = require('pretty-format');
var obj = { property: {} };
obj.circularReference = obj;
obj[Symbol('foo')] = 'foo';
obj.map = new Map();
obj.map.set('prop', 'value');
obj.array = [1, NaN, Infinity];
console.log(prettyFormat(obj));
```
**Result:**
```js
Object {
"property": Object {},
"circularReference": [Circular],
"map": Map {
"prop" => "value"
},
"array": Array [
1,
NaN,
Infinity
],
Symbol(foo): "foo"
}
```
#### Type Support
`Object`, `Array`, `ArrayBuffer`, `DataView`, `Float32Array`, `Float64Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Uint8Array`, `Uint8ClampedArray`, `Uint16Array`, `Uint32Array`, `arguments`, `Boolean`, `Date`, `Error`, `Function`, `Infinity`, `Map`, `NaN`, `null`, `Number`, `RegExp`, `Set`, `String`, `Symbol`, `undefined`, `WeakMap`, `WeakSet`
### API
```js
console.log(prettyFormat(object));
console.log(prettyFormat(object, options));
```
Options:
* **`callToJSON`**<br>
Type: `boolean`, default: `true`<br>
Call `toJSON()` on passed object.
* **`indent`**<br>
Type: `number`, default: `2`<br>
Number of spaces for indentation.
* **`maxDepth`**<br>
Type: `number`, default: `Infinity`<br>
Print only this number of levels.
* **`min`**<br>
Type: `boolean`, default: `false`<br>
Print without whitespace.
* **`plugins`**<br>
Type: `array`, default: `[]`<br>
Plugins (see the next section).
* **`printFunctionName`**<br>
Type: `boolean`, default: `true`<br>
Print function names or just `[Function]`.
* **`escapeRegex`**<br>
Type: `boolean`, default: `false`<br>
Escape special characters in regular expressions.
* **`highlight`**<br>
Type: `boolean`, default: `false`<br>
Highlight syntax for terminal (works only with `ReactTestComponent` and `ReactElement` plugins.
* **`theme`**<br>
Type: `object`, default: `{tag: 'cyan', content: 'reset'...}`<br>
Syntax highlight theme.<br>
Uses [ansi-styles colors](https://github.com/chalk/ansi-styles#colors) + `reset` for no color.<br>
Available types: `tag`, `content`, `prop` and `value`.
### Plugins
Pretty format also supports adding plugins:
```js
const fooPlugin = {
test(val) {
return val && val.hasOwnProperty('foo');
},
print(val, print, indent) {
return 'Foo: ' + print(val.foo);
}
};
const obj = {foo: {bar: {}}};
prettyFormat(obj, {
plugins: [fooPlugin]
});
// Foo: Object {
// "bar": Object {}
// }
```
#### `ReactTestComponent` and `ReactElement` plugins
```js
const prettyFormat = require('pretty-format');
const reactTestPlugin = require('pretty-format').plugins.ReactTestComponent;
const reactElementPlugin = require('pretty-format').plugins.ReactElement;
const React = require('react');
const renderer = require('react-test-renderer');
const element = React.createElement('h1', null, 'Hello World');
prettyFormat(renderer.create(element).toJSON(), {
plugins: [reactTestPlugin, reactElementPlugin]
});
// <h1>
// Hello World
// </h1>
```

View File

@@ -0,0 +1,970 @@
'use strict';var _keys = require('babel-runtime/core-js/object/keys');var _keys2 = _interopRequireDefault(_keys);var _typeof2 = require('babel-runtime/helpers/typeof');var _typeof3 = _interopRequireDefault(_typeof2);var _getOwnPropertySymbols = require('babel-runtime/core-js/object/get-own-property-symbols');var _getOwnPropertySymbols2 = _interopRequireDefault(_getOwnPropertySymbols);var _symbol = require('babel-runtime/core-js/symbol');var _symbol2 = _interopRequireDefault(_symbol);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var style = require('ansi-styles'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
var toString = Object.prototype.toString;
var toISOString = Date.prototype.toISOString;
var errorToString = Error.prototype.toString;
var regExpToString = RegExp.prototype.toString;
var symbolToString = _symbol2.default.prototype.toString;
var SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
var NEWLINE_REGEXP = /\n/gi;
var getSymbols = _getOwnPropertySymbols2.default || function (obj) {return [];};
function isToStringedArrayType(toStringed) {
return (
toStringed === '[object Array]' ||
toStringed === '[object ArrayBuffer]' ||
toStringed === '[object DataView]' ||
toStringed === '[object Float32Array]' ||
toStringed === '[object Float64Array]' ||
toStringed === '[object Int8Array]' ||
toStringed === '[object Int16Array]' ||
toStringed === '[object Int32Array]' ||
toStringed === '[object Uint8Array]' ||
toStringed === '[object Uint8ClampedArray]' ||
toStringed === '[object Uint16Array]' ||
toStringed === '[object Uint32Array]');
}
function printNumber(val) {
if (val != +val) {
return 'NaN';
}
var isNegativeZero = val === 0 && 1 / val < 0;
return isNegativeZero ? '-0' : '' + val;
}
function printFunction(val, printFunctionName) {
if (!printFunctionName) {
return '[Function]';
} else if (val.name === '') {
return '[Function anonymous]';
} else {
return '[Function ' + val.name + ']';
}
}
function printSymbol(val) {
return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
}
function printError(val) {
return '[' + errorToString.call(val) + ']';
}
function printBasicValue(
val,
printFunctionName,
escapeRegex)
{
if (val === true || val === false) {
return '' + val;
}
if (val === undefined) {
return 'undefined';
}
if (val === null) {
return 'null';
}
var typeOf = typeof val === 'undefined' ? 'undefined' : (0, _typeof3.default)(val);
if (typeOf === 'number') {
return printNumber(val);
}
if (typeOf === 'string') {
return '"' + val.replace(/"|\\/g, '\\$&') + '"';
}
if (typeOf === 'function') {
return printFunction(val, printFunctionName);
}
if (typeOf === 'symbol') {
return printSymbol(val);
}
var toStringed = toString.call(val);
if (toStringed === '[object WeakMap]') {
return 'WeakMap {}';
}
if (toStringed === '[object WeakSet]') {
return 'WeakSet {}';
}
if (
toStringed === '[object Function]' ||
toStringed === '[object GeneratorFunction]')
{
return printFunction(val, printFunctionName);
}
if (toStringed === '[object Symbol]') {
return printSymbol(val);
}
if (toStringed === '[object Date]') {
return toISOString.call(val);
}
if (toStringed === '[object Error]') {
return printError(val);
}
if (toStringed === '[object RegExp]') {
if (escapeRegex) {
// https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js
return regExpToString.call(val).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
}
return regExpToString.call(val);
}
if (toStringed === '[object Arguments]' && val.length === 0) {
return 'Arguments []';
}
if (isToStringedArrayType(toStringed) && val.length === 0) {
return val.constructor.name + ' []';
}
if (val instanceof Error) {
return printError(val);
}
return null;
}
function printList(
list,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
var body = '';
if (list.length) {
body += edgeSpacing;
var innerIndent = prevIndent + indent;
for (var i = 0; i < list.length; i++) {
body +=
innerIndent +
print(
list[i],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
if (i < list.length - 1) {
body += ',' + spacing;
}
}
body += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return '[' + body + ']';
}
function printArguments(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
return (
(min ? '' : 'Arguments ') +
printList(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors));
}
function printArray(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
return (
(min ? '' : val.constructor.name + ' ') +
printList(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors));
}
function printMap(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
var result = 'Map {';
var iterator = val.entries();
var current = iterator.next();
if (!current.done) {
result += edgeSpacing;
var innerIndent = prevIndent + indent;
while (!current.done) {
var key = print(
current.value[0],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
var _value = print(
current.value[1],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
result += innerIndent + key + ' => ' + _value;
current = iterator.next();
if (!current.done) {
result += ',' + spacing;
}
}
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return result + '}';
}
function printObject(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
var constructor = min ?
'' :
val.constructor ? val.constructor.name + ' ' : 'Object ';
var result = constructor + '{';
var keys = (0, _keys2.default)(val).sort();
var symbols = getSymbols(val);
if (symbols.length) {
keys = keys.
filter(
function (key) {return (
// $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value
!((typeof key === 'undefined' ? 'undefined' : (0, _typeof3.default)(key)) === 'symbol' ||
toString.call(key) === '[object Symbol]'));}).
concat(symbols);
}
if (keys.length) {
result += edgeSpacing;
var innerIndent = prevIndent + indent;
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var name = print(
key,
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
var _value2 = print(
val[key],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
result += innerIndent + name + ': ' + _value2;
if (i < keys.length - 1) {
result += ',' + spacing;
}
}
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return result + '}';
}
function printSet(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
var result = 'Set {';
var iterator = val.entries();
var current = iterator.next();
if (!current.done) {
result += edgeSpacing;
var innerIndent = prevIndent + indent;
while (!current.done) {
result +=
innerIndent +
print(
current.value[1],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
current = iterator.next();
if (!current.done) {
result += ',' + spacing;
}
}
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return result + '}';
}
function printComplexValue(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
refs = refs.slice();
if (refs.indexOf(val) > -1) {
return '[Circular]';
} else {
refs.push(val);
}
currentDepth++;
var hitMaxDepth = currentDepth > maxDepth;
if (
callToJSON &&
!hitMaxDepth &&
val.toJSON &&
typeof val.toJSON === 'function')
{
return print(
val.toJSON(),
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
var toStringed = toString.call(val);
if (toStringed === '[object Arguments]') {
return hitMaxDepth ?
'[Arguments]' :
printArguments(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
} else if (isToStringedArrayType(toStringed)) {
return hitMaxDepth ?
'[Array]' :
printArray(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
} else if (toStringed === '[object Map]') {
return hitMaxDepth ?
'[Map]' :
printMap(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
} else if (toStringed === '[object Set]') {
return hitMaxDepth ?
'[Set]' :
printSet(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
return hitMaxDepth ?
'[Object]' :
printObject(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
function printPlugin(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
var plugin = void 0;
for (var p = 0; p < plugins.length; p++) {
if (plugins[p].test(val)) {
plugin = plugins[p];
break;
}
}
if (!plugin) {
return null;
}
function boundPrint(val) {
return print(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
function boundIndent(str) {
var indentation = prevIndent + indent;
return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation);
}
var opts = {
edgeSpacing: edgeSpacing,
min: min,
spacing: spacing };
return plugin.print(val, boundPrint, boundIndent, opts, colors);
}
function print(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
var pluginsResult = printPlugin(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
if (typeof pluginsResult === 'string') {
return pluginsResult;
}
var basicResult = printBasicValue(val, printFunctionName, escapeRegex);
if (basicResult !== null) {
return basicResult;
}
return printComplexValue(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
var DEFAULTS = {
callToJSON: true,
edgeSpacing: '\n',
escapeRegex: false,
highlight: false,
indent: 2,
maxDepth: Infinity,
min: false,
plugins: [],
printFunctionName: true,
spacing: '\n',
theme: {
comment: 'gray',
content: 'reset',
prop: 'yellow',
tag: 'cyan',
value: 'green' } };
function validateOptions(opts) {
(0, _keys2.default)(opts).forEach(function (key) {
if (!DEFAULTS.hasOwnProperty(key)) {
throw new Error('pretty-format: Unknown option "' + key + '".');
}
});
if (opts.min && opts.indent !== undefined && opts.indent !== 0) {
throw new Error(
'pretty-format: Options "min" and "indent" cannot be used together.');
}
}
function normalizeOptions(opts) {
var result = {};
(0, _keys2.default)(DEFAULTS).forEach(
function (key) {return (
result[key] = opts.hasOwnProperty(key) ?
key === 'theme' ? normalizeTheme(opts.theme) : opts[key] :
DEFAULTS[key]);});
if (result.min) {
result.indent = 0;
}
// $FlowFixMe the type cast below means YOU are responsible to verify the code above.
return result;
}
function normalizeTheme(themeOption) {
if (!themeOption) {
throw new Error('pretty-format: Option "theme" must not be null.');
}
if ((typeof themeOption === 'undefined' ? 'undefined' : (0, _typeof3.default)(themeOption)) !== 'object') {
throw new Error('pretty-format: Option "theme" must be of type "object" but instead received "' + (typeof
themeOption === 'undefined' ? 'undefined' : (0, _typeof3.default)(themeOption)) + '".');
}
// Silently ignore any keys in `theme` that are not in defaults.
var themeRefined = themeOption;
var themeDefaults = DEFAULTS.theme;
return (0, _keys2.default)(themeDefaults).reduce(function (theme, key) {
theme[key] = Object.prototype.hasOwnProperty.call(themeOption, key) ?
themeRefined[key] :
themeDefaults[key];
return theme;
}, {});
}
function createIndent(indent) {
return new Array(indent + 1).join(' ');
}
function prettyFormat(val, initialOptions) {
var opts = void 0;
if (!initialOptions) {
opts = DEFAULTS;
} else {
validateOptions(initialOptions);
opts = normalizeOptions(initialOptions);
}
var colors = {
comment: { close: '', open: '' },
content: { close: '', open: '' },
prop: { close: '', open: '' },
tag: { close: '', open: '' },
value: { close: '', open: '' } };
(0, _keys2.default)(opts.theme).forEach(function (key) {
if (opts.highlight) {
var color = colors[key] = style[opts.theme[key]];
if (
!color ||
typeof color.close !== 'string' ||
typeof color.open !== 'string')
{
throw new Error('pretty-format: Option "theme" has a key "' +
key + '" whose value "' + opts.theme[key] + '" is undefined in ansi-styles.');
}
}
});
var indent = void 0;
var refs = void 0;
var prevIndent = '';
var currentDepth = 0;
var spacing = opts.min ? ' ' : '\n';
var edgeSpacing = opts.min ? '' : '\n';
if (opts && opts.plugins.length) {
indent = createIndent(opts.indent);
refs = [];
var pluginsResult = printPlugin(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
opts.maxDepth,
currentDepth,
opts.plugins,
opts.min,
opts.callToJSON,
opts.printFunctionName,
opts.escapeRegex,
colors);
if (typeof pluginsResult === 'string') {
return pluginsResult;
}
}
var basicResult = printBasicValue(
val,
opts.printFunctionName,
opts.escapeRegex);
if (basicResult !== null) {
return basicResult;
}
if (!indent) {
indent = createIndent(opts.indent);
}
if (!refs) {
refs = [];
}
return printComplexValue(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
opts.maxDepth,
currentDepth,
opts.plugins,
opts.min,
opts.callToJSON,
opts.printFunctionName,
opts.escapeRegex,
colors);
}
prettyFormat.plugins = {
AsymmetricMatcher: require('./plugins/AsymmetricMatcher'),
ConvertAnsi: require('./plugins/ConvertAnsi'),
HTMLElement: require('./plugins/HTMLElement'),
Immutable: require('./plugins/ImmutablePlugins'),
ReactElement: require('./plugins/ReactElement'),
ReactTestComponent: require('./plugins/ReactTestComponent') };
module.exports = prettyFormat;

View File

@@ -0,0 +1,55 @@
'use strict';var _assign = require('babel-runtime/core-js/object/assign');var _assign2 = _interopRequireDefault(_assign);var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);var _inherits2 = require('babel-runtime/helpers/inherits');var _inherits3 = _interopRequireDefault(_inherits2);var _for = require('babel-runtime/core-js/symbol/for');var _for2 = _interopRequireDefault(_for);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var asymmetricMatcher = (0, _for2.default)('jest.asymmetricMatcher'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var SPACE = ' ';var ArrayContaining = function (_Array) {(0, _inherits3.default)(ArrayContaining, _Array);function ArrayContaining() {(0, _classCallCheck3.default)(this, ArrayContaining);return (0, _possibleConstructorReturn3.default)(this, (ArrayContaining.__proto__ || (0, _getPrototypeOf2.default)(ArrayContaining)).apply(this, arguments));}return ArrayContaining;}(Array);var ObjectContaining = function (_Object) {(0, _inherits3.default)(ObjectContaining, _Object);function ObjectContaining() {(0, _classCallCheck3.default)(this, ObjectContaining);return (0, _possibleConstructorReturn3.default)(this, (ObjectContaining.__proto__ || (0, _getPrototypeOf2.default)(ObjectContaining)).apply(this, arguments));}return ObjectContaining;}(Object);var print = function print(val, _print,
indent,
opts,
colors)
{
var stringedValue = val.toString();
if (stringedValue === 'ArrayContaining') {
var array = ArrayContaining.from(val.sample);
return opts.spacing === SPACE ?
stringedValue + SPACE + _print(array) :
_print(array);
}
if (stringedValue === 'ObjectContaining') {
var object = (0, _assign2.default)(new ObjectContaining(), val.sample);
return opts.spacing === SPACE ?
stringedValue + SPACE + _print(object) :
_print(object);
}
if (stringedValue === 'StringMatching') {
return stringedValue + SPACE + _print(val.sample);
}
if (stringedValue === 'StringContaining') {
return stringedValue + SPACE + _print(val.sample);
}
return val.toAsymmetricMatcher();
};
var test = function test(object) {return object && object.$$typeof === asymmetricMatcher;};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,49 @@
'use strict';
var ansiRegex = require('ansi-regex'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var toHumanReadableAnsi = function toHumanReadableAnsi(text) {var style = require('ansi-styles');return text.replace(ansiRegex(), function (match, offset, string) {switch (match) {case style.red.close:case style.green.close:case style.reset.open:
case style.reset.close:
return '</>';
case style.red.open:
return '<red>';
case style.green.open:
return '<green>';
case style.dim.open:
return '<dim>';
case style.bold.open:
return '<bold>';
default:
return '';}
});
};
var test = function test(value) {return (
typeof value === 'string' && value.match(ansiRegex()));};
var print = function print(
val,
_print,
indent,
opts,
colors) {return (
_print(toHumanReadableAnsi(val)));};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,143 @@
'use strict';var _typeof2 = require('babel-runtime/helpers/typeof');var _typeof3 = _interopRequireDefault(_typeof2);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var escapeHTML = require('./lib/escapeHTML'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
var HTML_ELEMENT_REGEXP = /(HTML\w*?Element)|Text|Comment/;
var test = isHTMLElement;
function isHTMLElement(value) {
return (
value !== undefined &&
value !== null && (
value.nodeType === 1 || value.nodeType === 3 || value.nodeType === 8) &&
value.constructor !== undefined &&
value.constructor.name !== undefined &&
HTML_ELEMENT_REGEXP.test(value.constructor.name));
}
function printChildren(flatChildren, print, indent, colors, opts) {
return flatChildren.
map(function (node) {
if ((typeof node === 'undefined' ? 'undefined' : (0, _typeof3.default)(node)) === 'object') {
return print(node, print, indent, colors, opts);
} else if (typeof node === 'string') {
return colors.content.open + escapeHTML(node) + colors.content.close;
} else {
return print(node);
}
}).
filter(function (value) {return value.trim().length;}).
join(opts.edgeSpacing);
}
function printAttributes(attributes, indent, colors, opts) {
return attributes.
sort().
map(function (attribute) {
return (
opts.spacing +
indent(colors.prop.open + attribute.name + colors.prop.close + '=') +
colors.value.open + ('"' +
attribute.value + '"') +
colors.value.close);
}).
join('');
}
var print = function print(
element,
_print,
indent,
opts,
colors)
{
if (element.nodeType === 3) {
return element.data.
split('\n').
map(function (text) {return text.trimLeft();}).
filter(function (text) {return text.length;}).
join(' ');
} else if (element.nodeType === 8) {
return (
colors.comment.open +
'<!-- ' +
element.data.trim() +
' -->' +
colors.comment.close);
}
var result = colors.tag.open + '<';
var elementName = element.tagName.toLowerCase();
result += elementName + colors.tag.close;
var hasAttributes = element.attributes && element.attributes.length;
if (hasAttributes) {
var _attributes = Array.prototype.slice.call(element.attributes);
result += printAttributes(_attributes, indent, colors, opts);
}
var flatChildren = Array.prototype.slice.call(element.childNodes);
if (!flatChildren.length && element.textContent) {
flatChildren.push(element.textContent);
}
var closeInNewLine = hasAttributes && !opts.min;
if (flatChildren.length) {
var children = printChildren(flatChildren, _print, indent, colors, opts);
result +=
colors.tag.open + (
closeInNewLine ? '\n' : '') +
'>' +
colors.tag.close +
opts.edgeSpacing +
indent(children) +
opts.edgeSpacing +
colors.tag.open +
'</' +
elementName +
'>' +
colors.tag.close;
} else {
result +=
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close;
}
return result;
};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,26 @@
'use strict';
var printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var IS_LIST = '@@__IMMUTABLE_LIST__@@';var test = function test(maybeList) {return !!(maybeList && maybeList[IS_LIST]);};var print = function print(val, _print, indent,
opts,
colors) {return (
printImmutable(val, _print, indent, opts, colors, 'List', false));};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,28 @@
'use strict';
var printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var IS_MAP = '@@__IMMUTABLE_MAP__@@';var IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';var test = function test(maybeMap) {return !!(maybeMap && maybeMap[IS_MAP] && !maybeMap[IS_ORDERED]);};var print = function print(val,
_print,
indent,
opts,
colors) {return (
printImmutable(val, _print, indent, opts, colors, 'Map', true));};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,28 @@
'use strict';
var printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var IS_MAP = '@@__IMMUTABLE_MAP__@@';var IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';var test = function test(maybeOrderedMap) {return maybeOrderedMap && maybeOrderedMap[IS_MAP] && maybeOrderedMap[IS_ORDERED];};var print = function print(val,
_print,
indent,
opts,
colors) {return (
printImmutable(val, _print, indent, opts, colors, 'OrderedMap', true));};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,28 @@
'use strict';
var printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var IS_SET = '@@__IMMUTABLE_SET__@@';var IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';var test = function test(maybeOrderedSet) {return maybeOrderedSet && maybeOrderedSet[IS_SET] && maybeOrderedSet[IS_ORDERED];};var print = function print(val,
_print,
indent,
opts,
colors) {return (
printImmutable(val, _print, indent, opts, colors, 'OrderedSet', false));};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,17 @@
'use strict'; /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
module.exports = [
require('./ImmutableList'),
require('./ImmutableSet'),
require('./ImmutableMap'),
require('./ImmutableStack'),
require('./ImmutableOrderedSet'),
require('./ImmutableOrderedMap')];

View File

@@ -0,0 +1,28 @@
'use strict';
var printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var IS_SET = '@@__IMMUTABLE_SET__@@';var IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';var test = function test(maybeSet) {return !!(maybeSet && maybeSet[IS_SET] && !maybeSet[IS_ORDERED]);};var print = function print(val,
_print,
indent,
opts,
colors) {return (
printImmutable(val, _print, indent, opts, colors, 'Set', false));};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,26 @@
'use strict';
var printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var IS_STACK = '@@__IMMUTABLE_STACK__@@';var test = function test(maybeStack) {return !!(maybeStack && maybeStack[IS_STACK]);};var print = function print(val, _print, indent,
opts,
colors) {return (
printImmutable(val, _print, indent, opts, colors, 'Stack', false));};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,126 @@
'use strict';var _keys = require('babel-runtime/core-js/object/keys');var _keys2 = _interopRequireDefault(_keys);var _typeof2 = require('babel-runtime/helpers/typeof');var _typeof3 = _interopRequireDefault(_typeof2);var _for = require('babel-runtime/core-js/symbol/for');var _for2 = _interopRequireDefault(_for);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var escapeHTML = require('./lib/escapeHTML'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var reactElement = (0, _for2.default)('react.element');function traverseChildren(opaqueChildren, cb) {if (Array.isArray(opaqueChildren)) {opaqueChildren.forEach(function (child) {return traverseChildren(child, cb);});} else if (opaqueChildren != null && opaqueChildren !== false) {cb(opaqueChildren);
}
}
function printChildren(flatChildren, print, indent, colors, opts) {
return flatChildren.
map(function (node) {
if ((typeof node === 'undefined' ? 'undefined' : (0, _typeof3.default)(node)) === 'object') {
return print(node, print, indent, colors, opts);
} else if (typeof node === 'string') {
return colors.content.open + escapeHTML(node) + colors.content.close;
} else {
return print(node);
}
}).
join(opts.edgeSpacing);
}
function printProps(props, print, indent, colors, opts) {
return (0, _keys2.default)(props).
sort().
map(function (name) {
if (name === 'children') {
return '';
}
var prop = props[name];
var printed = print(prop);
if (typeof prop !== 'string') {
if (printed.indexOf('\n') !== -1) {
printed =
'{' +
opts.edgeSpacing +
indent(indent(printed) + opts.edgeSpacing + '}');
} else {
printed = '{' + printed + '}';
}
}
return (
opts.spacing +
indent(colors.prop.open + name + colors.prop.close + '=') +
colors.value.open +
printed +
colors.value.close);
}).
join('');
}
var print = function print(
element,
_print,
indent,
opts,
colors)
{
var result = colors.tag.open + '<';
var elementName = void 0;
if (typeof element.type === 'string') {
elementName = element.type;
} else if (typeof element.type === 'function') {
elementName = element.type.displayName || element.type.name || 'Unknown';
} else {
elementName = 'Unknown';
}
result += elementName + colors.tag.close;
result += printProps(element.props, _print, indent, colors, opts);
var opaqueChildren = element.props.children;
var hasProps = !!(0, _keys2.default)(element.props).filter(
function (propName) {return propName !== 'children';}).
length;
var closeInNewLine = hasProps && !opts.min;
if (opaqueChildren) {
var flatChildren = [];
traverseChildren(opaqueChildren, function (child) {
flatChildren.push(child);
});
var children = printChildren(flatChildren, _print, indent, colors, opts);
result +=
colors.tag.open + (
closeInNewLine ? '\n' : '') +
'>' +
colors.tag.close +
opts.edgeSpacing +
indent(children) +
opts.edgeSpacing +
colors.tag.open +
'</' +
elementName +
'>' +
colors.tag.close;
} else {
result +=
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close;
}
return result;
};
var test = function test(object) {return object && object.$$typeof === reactElement;};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,121 @@
'use strict';var _keys = require('babel-runtime/core-js/object/keys');var _keys2 = _interopRequireDefault(_keys);var _for = require('babel-runtime/core-js/symbol/for');var _for2 = _interopRequireDefault(_for);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var escapeHTML = require('./lib/escapeHTML'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var reactTestInstance = (0, _for2.default)('react.test.json');function printChildren(children, print, indent, colors,
opts)
{
return children.
map(function (child) {return printInstance(child, print, indent, colors, opts);}).
join(opts.edgeSpacing);
}
function printProps(props, print, indent, colors, opts) {
return (0, _keys2.default)(props).
sort().
map(function (name) {
var prop = props[name];
var printed = print(prop);
if (typeof prop !== 'string') {
if (printed.indexOf('\n') !== -1) {
printed =
'{' +
opts.edgeSpacing +
indent(indent(printed) + opts.edgeSpacing + '}');
} else {
printed = '{' + printed + '}';
}
}
return (
opts.spacing +
indent(colors.prop.open + name + colors.prop.close + '=') +
colors.value.open +
printed +
colors.value.close);
}).
join('');
}
function printInstance(instance, print, indent, colors, opts) {
if (typeof instance == 'number') {
return print(instance);
} else if (typeof instance === 'string') {
return colors.content.open + escapeHTML(instance) + colors.content.close;
}
var closeInNewLine = false;
var result = colors.tag.open + '<' + instance.type + colors.tag.close;
if (instance.props) {
closeInNewLine = !!(0, _keys2.default)(instance.props).length && !opts.min;
result += printProps(instance.props, print, indent, colors, opts);
}
if (instance.children) {
var children = printChildren(
instance.children,
print,
indent,
colors,
opts);
result +=
colors.tag.open + (
closeInNewLine ? '\n' : '') +
'>' +
colors.tag.close +
opts.edgeSpacing +
indent(children) +
opts.edgeSpacing +
colors.tag.open +
'</' +
instance.type +
'>' +
colors.tag.close;
} else {
result +=
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close;
}
return result;
}
var print = function print(
val,
_print,
indent,
opts,
colors) {return (
printInstance(val, _print, indent, colors, opts));};
var test = function test(object) {return (
object && object.$$typeof === reactTestInstance);};
module.exports = { print: print, test: test };

View File

@@ -0,0 +1,15 @@
'use strict'; /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function escapeHTML(str) {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
module.exports = escapeHTML;

View File

@@ -0,0 +1,57 @@
'use strict';var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
var IMMUTABLE_NAMESPACE = 'Immutable.'; /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/var SPACE = ' ';var addKey = function addKey(isMap, key) {return isMap ? key + ': ' : '';};var addFinalEdgeSpacing = function addFinalEdgeSpacing(length, edgeSpacing) {return length > 0 ? edgeSpacing : '';};var printImmutable = function printImmutable(
val,
print,
indent,
opts,
colors,
immutableDataStructureName,
isMap)
{var _ref =
isMap ? ['{', '}'] : ['[', ']'],_ref2 = (0, _slicedToArray3.default)(_ref, 2),openTag = _ref2[0],closeTag = _ref2[1];
var result =
IMMUTABLE_NAMESPACE +
immutableDataStructureName +
SPACE +
openTag +
opts.edgeSpacing;
var immutableArray = [];
val.forEach(function (item, key) {return (
immutableArray.push(
indent(addKey(isMap, key) + print(item, print, indent, opts, colors))));});
result += immutableArray.join(',' + opts.spacing);
if (!opts.min && immutableArray.length > 0) {
result += ',';
}
return (
result +
addFinalEdgeSpacing(immutableArray.length, opts.edgeSpacing) +
closeTag);
};
module.exports = printImmutable;

View File

@@ -0,0 +1,970 @@
'use strict';
const style = require('ansi-styles'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
const toString = Object.prototype.toString;
const toISOString = Date.prototype.toISOString;
const errorToString = Error.prototype.toString;
const regExpToString = RegExp.prototype.toString;
const symbolToString = Symbol.prototype.toString;
const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
const NEWLINE_REGEXP = /\n/gi;
const getSymbols = Object.getOwnPropertySymbols || (obj => []);
function isToStringedArrayType(toStringed) {
return (
toStringed === '[object Array]' ||
toStringed === '[object ArrayBuffer]' ||
toStringed === '[object DataView]' ||
toStringed === '[object Float32Array]' ||
toStringed === '[object Float64Array]' ||
toStringed === '[object Int8Array]' ||
toStringed === '[object Int16Array]' ||
toStringed === '[object Int32Array]' ||
toStringed === '[object Uint8Array]' ||
toStringed === '[object Uint8ClampedArray]' ||
toStringed === '[object Uint16Array]' ||
toStringed === '[object Uint32Array]');
}
function printNumber(val) {
if (val != +val) {
return 'NaN';
}
const isNegativeZero = val === 0 && 1 / val < 0;
return isNegativeZero ? '-0' : '' + val;
}
function printFunction(val, printFunctionName) {
if (!printFunctionName) {
return '[Function]';
} else if (val.name === '') {
return '[Function anonymous]';
} else {
return '[Function ' + val.name + ']';
}
}
function printSymbol(val) {
return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
}
function printError(val) {
return '[' + errorToString.call(val) + ']';
}
function printBasicValue(
val,
printFunctionName,
escapeRegex)
{
if (val === true || val === false) {
return '' + val;
}
if (val === undefined) {
return 'undefined';
}
if (val === null) {
return 'null';
}
const typeOf = typeof val;
if (typeOf === 'number') {
return printNumber(val);
}
if (typeOf === 'string') {
return '"' + val.replace(/"|\\/g, '\\$&') + '"';
}
if (typeOf === 'function') {
return printFunction(val, printFunctionName);
}
if (typeOf === 'symbol') {
return printSymbol(val);
}
const toStringed = toString.call(val);
if (toStringed === '[object WeakMap]') {
return 'WeakMap {}';
}
if (toStringed === '[object WeakSet]') {
return 'WeakSet {}';
}
if (
toStringed === '[object Function]' ||
toStringed === '[object GeneratorFunction]')
{
return printFunction(val, printFunctionName);
}
if (toStringed === '[object Symbol]') {
return printSymbol(val);
}
if (toStringed === '[object Date]') {
return toISOString.call(val);
}
if (toStringed === '[object Error]') {
return printError(val);
}
if (toStringed === '[object RegExp]') {
if (escapeRegex) {
// https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js
return regExpToString.call(val).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
}
return regExpToString.call(val);
}
if (toStringed === '[object Arguments]' && val.length === 0) {
return 'Arguments []';
}
if (isToStringedArrayType(toStringed) && val.length === 0) {
return val.constructor.name + ' []';
}
if (val instanceof Error) {
return printError(val);
}
return null;
}
function printList(
list,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
let body = '';
if (list.length) {
body += edgeSpacing;
const innerIndent = prevIndent + indent;
for (let i = 0; i < list.length; i++) {
body +=
innerIndent +
print(
list[i],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
if (i < list.length - 1) {
body += ',' + spacing;
}
}
body += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return '[' + body + ']';
}
function printArguments(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
return (
(min ? '' : 'Arguments ') +
printList(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors));
}
function printArray(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
return (
(min ? '' : val.constructor.name + ' ') +
printList(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors));
}
function printMap(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
let result = 'Map {';
const iterator = val.entries();
let current = iterator.next();
if (!current.done) {
result += edgeSpacing;
const innerIndent = prevIndent + indent;
while (!current.done) {
const key = print(
current.value[0],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
const value = print(
current.value[1],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
result += innerIndent + key + ' => ' + value;
current = iterator.next();
if (!current.done) {
result += ',' + spacing;
}
}
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return result + '}';
}
function printObject(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
const constructor = min ?
'' :
val.constructor ? val.constructor.name + ' ' : 'Object ';
let result = constructor + '{';
let keys = Object.keys(val).sort();
const symbols = getSymbols(val);
if (symbols.length) {
keys = keys.
filter(
key =>
// $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value
!(typeof key === 'symbol' ||
toString.call(key) === '[object Symbol]')).
concat(symbols);
}
if (keys.length) {
result += edgeSpacing;
const innerIndent = prevIndent + indent;
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const name = print(
key,
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
const value = print(
val[key],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
result += innerIndent + name + ': ' + value;
if (i < keys.length - 1) {
result += ',' + spacing;
}
}
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return result + '}';
}
function printSet(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
let result = 'Set {';
const iterator = val.entries();
let current = iterator.next();
if (!current.done) {
result += edgeSpacing;
const innerIndent = prevIndent + indent;
while (!current.done) {
result +=
innerIndent +
print(
current.value[1],
indent,
innerIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
current = iterator.next();
if (!current.done) {
result += ',' + spacing;
}
}
result += (min ? '' : ',') + edgeSpacing + prevIndent;
}
return result + '}';
}
function printComplexValue(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
refs = refs.slice();
if (refs.indexOf(val) > -1) {
return '[Circular]';
} else {
refs.push(val);
}
currentDepth++;
const hitMaxDepth = currentDepth > maxDepth;
if (
callToJSON &&
!hitMaxDepth &&
val.toJSON &&
typeof val.toJSON === 'function')
{
return print(
val.toJSON(),
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
const toStringed = toString.call(val);
if (toStringed === '[object Arguments]') {
return hitMaxDepth ?
'[Arguments]' :
printArguments(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
} else if (isToStringedArrayType(toStringed)) {
return hitMaxDepth ?
'[Array]' :
printArray(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
} else if (toStringed === '[object Map]') {
return hitMaxDepth ?
'[Map]' :
printMap(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
} else if (toStringed === '[object Set]') {
return hitMaxDepth ?
'[Set]' :
printSet(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
return hitMaxDepth ?
'[Object]' :
printObject(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
function printPlugin(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
let plugin;
for (let p = 0; p < plugins.length; p++) {
if (plugins[p].test(val)) {
plugin = plugins[p];
break;
}
}
if (!plugin) {
return null;
}
function boundPrint(val) {
return print(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
function boundIndent(str) {
const indentation = prevIndent + indent;
return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation);
}
const opts = {
edgeSpacing,
min,
spacing };
return plugin.print(val, boundPrint, boundIndent, opts, colors);
}
function print(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors)
{
const pluginsResult = printPlugin(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
if (typeof pluginsResult === 'string') {
return pluginsResult;
}
const basicResult = printBasicValue(val, printFunctionName, escapeRegex);
if (basicResult !== null) {
return basicResult;
}
return printComplexValue(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
maxDepth,
currentDepth,
plugins,
min,
callToJSON,
printFunctionName,
escapeRegex,
colors);
}
const DEFAULTS = {
callToJSON: true,
edgeSpacing: '\n',
escapeRegex: false,
highlight: false,
indent: 2,
maxDepth: Infinity,
min: false,
plugins: [],
printFunctionName: true,
spacing: '\n',
theme: {
comment: 'gray',
content: 'reset',
prop: 'yellow',
tag: 'cyan',
value: 'green' } };
function validateOptions(opts) {
Object.keys(opts).forEach(key => {
if (!DEFAULTS.hasOwnProperty(key)) {
throw new Error(`pretty-format: Unknown option "${key}".`);
}
});
if (opts.min && opts.indent !== undefined && opts.indent !== 0) {
throw new Error(
'pretty-format: Options "min" and "indent" cannot be used together.');
}
}
function normalizeOptions(opts) {
const result = {};
Object.keys(DEFAULTS).forEach(
key =>
result[key] = opts.hasOwnProperty(key) ?
key === 'theme' ? normalizeTheme(opts.theme) : opts[key] :
DEFAULTS[key]);
if (result.min) {
result.indent = 0;
}
// $FlowFixMe the type cast below means YOU are responsible to verify the code above.
return result;
}
function normalizeTheme(themeOption) {
if (!themeOption) {
throw new Error(`pretty-format: Option "theme" must not be null.`);
}
if (typeof themeOption !== 'object') {
throw new Error(
`pretty-format: Option "theme" must be of type "object" but instead received "${typeof themeOption}".`);
}
// Silently ignore any keys in `theme` that are not in defaults.
const themeRefined = themeOption;
const themeDefaults = DEFAULTS.theme;
return Object.keys(themeDefaults).reduce((theme, key) => {
theme[key] = Object.prototype.hasOwnProperty.call(themeOption, key) ?
themeRefined[key] :
themeDefaults[key];
return theme;
}, {});
}
function createIndent(indent) {
return new Array(indent + 1).join(' ');
}
function prettyFormat(val, initialOptions) {
let opts;
if (!initialOptions) {
opts = DEFAULTS;
} else {
validateOptions(initialOptions);
opts = normalizeOptions(initialOptions);
}
const colors = {
comment: { close: '', open: '' },
content: { close: '', open: '' },
prop: { close: '', open: '' },
tag: { close: '', open: '' },
value: { close: '', open: '' } };
Object.keys(opts.theme).forEach(key => {
if (opts.highlight) {
const color = colors[key] = style[opts.theme[key]];
if (
!color ||
typeof color.close !== 'string' ||
typeof color.open !== 'string')
{
throw new Error(
`pretty-format: Option "theme" has a key "${key}" whose value "${opts.theme[key]}" is undefined in ansi-styles.`);
}
}
});
let indent;
let refs;
const prevIndent = '';
const currentDepth = 0;
const spacing = opts.min ? ' ' : '\n';
const edgeSpacing = opts.min ? '' : '\n';
if (opts && opts.plugins.length) {
indent = createIndent(opts.indent);
refs = [];
const pluginsResult = printPlugin(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
opts.maxDepth,
currentDepth,
opts.plugins,
opts.min,
opts.callToJSON,
opts.printFunctionName,
opts.escapeRegex,
colors);
if (typeof pluginsResult === 'string') {
return pluginsResult;
}
}
const basicResult = printBasicValue(
val,
opts.printFunctionName,
opts.escapeRegex);
if (basicResult !== null) {
return basicResult;
}
if (!indent) {
indent = createIndent(opts.indent);
}
if (!refs) {
refs = [];
}
return printComplexValue(
val,
indent,
prevIndent,
spacing,
edgeSpacing,
refs,
opts.maxDepth,
currentDepth,
opts.plugins,
opts.min,
opts.callToJSON,
opts.printFunctionName,
opts.escapeRegex,
colors);
}
prettyFormat.plugins = {
AsymmetricMatcher: require('./plugins/AsymmetricMatcher'),
ConvertAnsi: require('./plugins/ConvertAnsi'),
HTMLElement: require('./plugins/HTMLElement'),
Immutable: require('./plugins/ImmutablePlugins'),
ReactElement: require('./plugins/ReactElement'),
ReactTestComponent: require('./plugins/ReactTestComponent') };
module.exports = prettyFormat;

View File

@@ -0,0 +1,55 @@
'use strict';
const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const SPACE = ' ';class ArrayContaining extends Array {}class ObjectContaining extends Object {}const print = (val, print,
indent,
opts,
colors) =>
{
const stringedValue = val.toString();
if (stringedValue === 'ArrayContaining') {
const array = ArrayContaining.from(val.sample);
return opts.spacing === SPACE ?
stringedValue + SPACE + print(array) :
print(array);
}
if (stringedValue === 'ObjectContaining') {
const object = Object.assign(new ObjectContaining(), val.sample);
return opts.spacing === SPACE ?
stringedValue + SPACE + print(object) :
print(object);
}
if (stringedValue === 'StringMatching') {
return stringedValue + SPACE + print(val.sample);
}
if (stringedValue === 'StringContaining') {
return stringedValue + SPACE + print(val.sample);
}
return val.toAsymmetricMatcher();
};
const test = object => object && object.$$typeof === asymmetricMatcher;
module.exports = { print, test };

View File

@@ -0,0 +1,49 @@
'use strict';
const ansiRegex = require('ansi-regex'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const toHumanReadableAnsi = text => {const style = require('ansi-styles');return text.replace(ansiRegex(), (match, offset, string) => {switch (match) {case style.red.close:case style.green.close:case style.reset.open:
case style.reset.close:
return '</>';
case style.red.open:
return '<red>';
case style.green.open:
return '<green>';
case style.dim.open:
return '<dim>';
case style.bold.open:
return '<bold>';
default:
return '';}
});
};
const test = value =>
typeof value === 'string' && value.match(ansiRegex());
const print = (
val,
print,
indent,
opts,
colors) =>
print(toHumanReadableAnsi(val));
module.exports = { print, test };

View File

@@ -0,0 +1,143 @@
'use strict';
const escapeHTML = require('./lib/escapeHTML'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
const HTML_ELEMENT_REGEXP = /(HTML\w*?Element)|Text|Comment/;
const test = isHTMLElement;
function isHTMLElement(value) {
return (
value !== undefined &&
value !== null && (
value.nodeType === 1 || value.nodeType === 3 || value.nodeType === 8) &&
value.constructor !== undefined &&
value.constructor.name !== undefined &&
HTML_ELEMENT_REGEXP.test(value.constructor.name));
}
function printChildren(flatChildren, print, indent, colors, opts) {
return flatChildren.
map(node => {
if (typeof node === 'object') {
return print(node, print, indent, colors, opts);
} else if (typeof node === 'string') {
return colors.content.open + escapeHTML(node) + colors.content.close;
} else {
return print(node);
}
}).
filter(value => value.trim().length).
join(opts.edgeSpacing);
}
function printAttributes(attributes, indent, colors, opts) {
return attributes.
sort().
map(attribute => {
return (
opts.spacing +
indent(colors.prop.open + attribute.name + colors.prop.close + '=') +
colors.value.open +
`"${attribute.value}"` +
colors.value.close);
}).
join('');
}
const print = (
element,
print,
indent,
opts,
colors) =>
{
if (element.nodeType === 3) {
return element.data.
split('\n').
map(text => text.trimLeft()).
filter(text => text.length).
join(' ');
} else if (element.nodeType === 8) {
return (
colors.comment.open +
'<!-- ' +
element.data.trim() +
' -->' +
colors.comment.close);
}
let result = colors.tag.open + '<';
const elementName = element.tagName.toLowerCase();
result += elementName + colors.tag.close;
const hasAttributes = element.attributes && element.attributes.length;
if (hasAttributes) {
const attributes = Array.prototype.slice.call(element.attributes);
result += printAttributes(attributes, indent, colors, opts);
}
const flatChildren = Array.prototype.slice.call(element.childNodes);
if (!flatChildren.length && element.textContent) {
flatChildren.push(element.textContent);
}
const closeInNewLine = hasAttributes && !opts.min;
if (flatChildren.length) {
const children = printChildren(flatChildren, print, indent, colors, opts);
result +=
colors.tag.open + (
closeInNewLine ? '\n' : '') +
'>' +
colors.tag.close +
opts.edgeSpacing +
indent(children) +
opts.edgeSpacing +
colors.tag.open +
'</' +
elementName +
'>' +
colors.tag.close;
} else {
result +=
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close;
}
return result;
};
module.exports = { print, test };

View File

@@ -0,0 +1,26 @@
'use strict';
const printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const IS_LIST = '@@__IMMUTABLE_LIST__@@';const test = maybeList => !!(maybeList && maybeList[IS_LIST]);const print = (val, print, indent,
opts,
colors) =>
printImmutable(val, print, indent, opts, colors, 'List', false);
module.exports = { print, test };

View File

@@ -0,0 +1,28 @@
'use strict';
const printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const IS_MAP = '@@__IMMUTABLE_MAP__@@';const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';const test = maybeMap => !!(maybeMap && maybeMap[IS_MAP] && !maybeMap[IS_ORDERED]);const print = (val,
print,
indent,
opts,
colors) =>
printImmutable(val, print, indent, opts, colors, 'Map', true);
module.exports = { print, test };

View File

@@ -0,0 +1,28 @@
'use strict';
const printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const IS_MAP = '@@__IMMUTABLE_MAP__@@';const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';const test = maybeOrderedMap => maybeOrderedMap && maybeOrderedMap[IS_MAP] && maybeOrderedMap[IS_ORDERED];const print = (val,
print,
indent,
opts,
colors) =>
printImmutable(val, print, indent, opts, colors, 'OrderedMap', true);
module.exports = { print, test };

View File

@@ -0,0 +1,28 @@
'use strict';
const printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const IS_SET = '@@__IMMUTABLE_SET__@@';const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';const test = maybeOrderedSet => maybeOrderedSet && maybeOrderedSet[IS_SET] && maybeOrderedSet[IS_ORDERED];const print = (val,
print,
indent,
opts,
colors) =>
printImmutable(val, print, indent, opts, colors, 'OrderedSet', false);
module.exports = { print, test };

View File

@@ -0,0 +1,17 @@
'use strict'; /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
module.exports = [
require('./ImmutableList'),
require('./ImmutableSet'),
require('./ImmutableMap'),
require('./ImmutableStack'),
require('./ImmutableOrderedSet'),
require('./ImmutableOrderedMap')];

View File

@@ -0,0 +1,28 @@
'use strict';
const printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const IS_SET = '@@__IMMUTABLE_SET__@@';const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';const test = maybeSet => !!(maybeSet && maybeSet[IS_SET] && !maybeSet[IS_ORDERED]);const print = (val,
print,
indent,
opts,
colors) =>
printImmutable(val, print, indent, opts, colors, 'Set', false);
module.exports = { print, test };

View File

@@ -0,0 +1,26 @@
'use strict';
const printImmutable = require('./lib/printImmutable'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const IS_STACK = '@@__IMMUTABLE_STACK__@@';const test = maybeStack => !!(maybeStack && maybeStack[IS_STACK]);const print = (val, print, indent,
opts,
colors) =>
printImmutable(val, print, indent, opts, colors, 'Stack', false);
module.exports = { print, test };

View File

@@ -0,0 +1,126 @@
'use strict';
const escapeHTML = require('./lib/escapeHTML'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const reactElement = Symbol.for('react.element');function traverseChildren(opaqueChildren, cb) {if (Array.isArray(opaqueChildren)) {opaqueChildren.forEach(child => traverseChildren(child, cb));} else if (opaqueChildren != null && opaqueChildren !== false) {cb(opaqueChildren);
}
}
function printChildren(flatChildren, print, indent, colors, opts) {
return flatChildren.
map(node => {
if (typeof node === 'object') {
return print(node, print, indent, colors, opts);
} else if (typeof node === 'string') {
return colors.content.open + escapeHTML(node) + colors.content.close;
} else {
return print(node);
}
}).
join(opts.edgeSpacing);
}
function printProps(props, print, indent, colors, opts) {
return Object.keys(props).
sort().
map(name => {
if (name === 'children') {
return '';
}
const prop = props[name];
let printed = print(prop);
if (typeof prop !== 'string') {
if (printed.indexOf('\n') !== -1) {
printed =
'{' +
opts.edgeSpacing +
indent(indent(printed) + opts.edgeSpacing + '}');
} else {
printed = '{' + printed + '}';
}
}
return (
opts.spacing +
indent(colors.prop.open + name + colors.prop.close + '=') +
colors.value.open +
printed +
colors.value.close);
}).
join('');
}
const print = (
element,
print,
indent,
opts,
colors) =>
{
let result = colors.tag.open + '<';
let elementName;
if (typeof element.type === 'string') {
elementName = element.type;
} else if (typeof element.type === 'function') {
elementName = element.type.displayName || element.type.name || 'Unknown';
} else {
elementName = 'Unknown';
}
result += elementName + colors.tag.close;
result += printProps(element.props, print, indent, colors, opts);
const opaqueChildren = element.props.children;
const hasProps = !!Object.keys(element.props).filter(
propName => propName !== 'children').
length;
const closeInNewLine = hasProps && !opts.min;
if (opaqueChildren) {
const flatChildren = [];
traverseChildren(opaqueChildren, child => {
flatChildren.push(child);
});
const children = printChildren(flatChildren, print, indent, colors, opts);
result +=
colors.tag.open + (
closeInNewLine ? '\n' : '') +
'>' +
colors.tag.close +
opts.edgeSpacing +
indent(children) +
opts.edgeSpacing +
colors.tag.open +
'</' +
elementName +
'>' +
colors.tag.close;
} else {
result +=
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close;
}
return result;
};
const test = object => object && object.$$typeof === reactElement;
module.exports = { print, test };

View File

@@ -0,0 +1,121 @@
'use strict';
const escapeHTML = require('./lib/escapeHTML'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const reactTestInstance = Symbol.for('react.test.json');function printChildren(children, print, indent, colors,
opts)
{
return children.
map(child => printInstance(child, print, indent, colors, opts)).
join(opts.edgeSpacing);
}
function printProps(props, print, indent, colors, opts) {
return Object.keys(props).
sort().
map(name => {
const prop = props[name];
let printed = print(prop);
if (typeof prop !== 'string') {
if (printed.indexOf('\n') !== -1) {
printed =
'{' +
opts.edgeSpacing +
indent(indent(printed) + opts.edgeSpacing + '}');
} else {
printed = '{' + printed + '}';
}
}
return (
opts.spacing +
indent(colors.prop.open + name + colors.prop.close + '=') +
colors.value.open +
printed +
colors.value.close);
}).
join('');
}
function printInstance(instance, print, indent, colors, opts) {
if (typeof instance == 'number') {
return print(instance);
} else if (typeof instance === 'string') {
return colors.content.open + escapeHTML(instance) + colors.content.close;
}
let closeInNewLine = false;
let result = colors.tag.open + '<' + instance.type + colors.tag.close;
if (instance.props) {
closeInNewLine = !!Object.keys(instance.props).length && !opts.min;
result += printProps(instance.props, print, indent, colors, opts);
}
if (instance.children) {
const children = printChildren(
instance.children,
print,
indent,
colors,
opts);
result +=
colors.tag.open + (
closeInNewLine ? '\n' : '') +
'>' +
colors.tag.close +
opts.edgeSpacing +
indent(children) +
opts.edgeSpacing +
colors.tag.open +
'</' +
instance.type +
'>' +
colors.tag.close;
} else {
result +=
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close;
}
return result;
}
const print = (
val,
print,
indent,
opts,
colors) =>
printInstance(val, print, indent, colors, opts);
const test = object =>
object && object.$$typeof === reactTestInstance;
module.exports = { print, test };

View File

@@ -0,0 +1,15 @@
'use strict'; /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function escapeHTML(str) {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
module.exports = escapeHTML;

View File

@@ -0,0 +1,57 @@
'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();
const IMMUTABLE_NAMESPACE = 'Immutable.'; /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const SPACE = ' ';const addKey = (isMap, key) => isMap ? key + ': ' : '';const addFinalEdgeSpacing = (length, edgeSpacing) => length > 0 ? edgeSpacing : '';const printImmutable = (
val,
print,
indent,
opts,
colors,
immutableDataStructureName,
isMap) =>
{var _ref =
isMap ? ['{', '}'] : ['[', ']'],_ref2 = _slicedToArray(_ref, 2);const openTag = _ref2[0],closeTag = _ref2[1];
let result =
IMMUTABLE_NAMESPACE +
immutableDataStructureName +
SPACE +
openTag +
opts.edgeSpacing;
const immutableArray = [];
val.forEach((item, key) =>
immutableArray.push(
indent(addKey(isMap, key) + print(item, print, indent, opts, colors))));
result += immutableArray.join(',' + opts.spacing);
if (!opts.min && immutableArray.length > 0) {
result += ',';
}
return (
result +
addFinalEdgeSpacing(immutableArray.length, opts.edgeSpacing) +
closeTag);
};
module.exports = printImmutable;

View File

@@ -0,0 +1,56 @@
{
"_args": [
[
"pretty-format@20.0.3",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "pretty-format@20.0.3",
"_id": "pretty-format@20.0.3",
"_inBundle": false,
"_integrity": "sha1-Ag41ClYKH+GpjcO+tsz/s4beixQ=",
"_location": "/react-scripts/pretty-format",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "pretty-format@20.0.3",
"name": "pretty-format",
"escapedName": "pretty-format",
"rawSpec": "20.0.3",
"saveSpec": null,
"fetchSpec": "20.0.3"
},
"_requiredBy": [
"/react-scripts/jest-config",
"/react-scripts/jest-diff",
"/react-scripts/jest-matcher-utils",
"/react-scripts/jest-snapshot",
"/react-scripts/jest-validate"
],
"_resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-20.0.3.tgz",
"_spec": "20.0.3",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "James Kyle",
"email": "me@thejameskyle.com"
},
"browser": "build-es5/index.js",
"bugs": {
"url": "https://github.com/facebook/jest/issues"
},
"dependencies": {
"ansi-regex": "^2.1.1",
"ansi-styles": "^3.0.0"
},
"description": "Stringify any JavaScript value.",
"homepage": "https://github.com/facebook/jest#readme",
"license": "BSD-3-Clause",
"main": "build/index.js",
"name": "pretty-format",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/jest.git"
},
"version": "20.0.3"
}

View File

@@ -0,0 +1,213 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
const util = require('util');
const chalk = require('chalk');
const React = require('react');
const ReactTestRenderer = require('react-test-renderer');
const leftPad = require('left-pad');
const prettyFormat = require('../build');
const ReactTestComponent = require('../build/plugins/ReactTestComponent');
const worldGeoJson = require('./world.geo.json');
const NANOSECONDS = 1000000000;
let TIMES_TO_RUN = 100000;
function testCase(name, fn) {
let result, error, time, total;
try {
result = fn();
} catch (err) {
error = err;
}
if (!error) {
const start = process.hrtime();
for (let i = 0; i < TIMES_TO_RUN; i++) {
fn();
}
const diff = process.hrtime(start);
total = diff[0] * 1e9 + diff[1];
time = Math.round(total / TIMES_TO_RUN);
}
return {
error,
name,
result,
time,
total,
};
}
function test(name, value, ignoreResult, prettyFormatOpts) {
const formatted = testCase(
'prettyFormat() ',
() => prettyFormat(value, prettyFormatOpts)
);
const inspected = testCase('util.inspect() ', () => {
return util.inspect(value, {
depth: null,
showHidden: true,
});
});
const stringified = testCase('JSON.stringify()', () => {
return JSON.stringify(value, null, ' ');
});
const results = [formatted, inspected, stringified].sort((a, b) => {
return a.time - b.time;
});
const winner = results[0];
results.forEach((item, index) => {
item.isWinner = index === 0;
item.isLoser = index === results.length - 1;
});
function log(current) {
let message = current.name;
if (current.time) {
message += ' - ' + leftPad(current.time, 6) + 'ns';
}
if (current.total) {
message +=
' - ' + (current.total / NANOSECONDS) + 's total (' +
TIMES_TO_RUN + ' runs)';
}
if (current.error) {
message += ' - Error: ' + current.error.message;
}
if (!ignoreResult && current.result) {
message += ' - ' + JSON.stringify(current.result);
}
message = ' ' + message + ' ';
if (current.error) {
message = chalk.dim(message);
}
const diff = (current.time - winner.time);
if (diff > (winner.time * 0.85)) {
message = chalk.bgRed.black(message);
} else if (diff > (winner.time * 0.65)) {
message = chalk.bgYellow.black(message);
} else if (!current.error) {
message = chalk.bgGreen.black(message);
} else {
message = chalk.dim(message);
}
console.log(' ' + message);
}
console.log(name + ': ');
results.forEach(log);
console.log();
}
function returnArguments() {
return arguments;
}
test('empty arguments', returnArguments());
test('arguments', returnArguments(1, 2, 3));
test('an empty array', []);
test('an array with items', [1, 2, 3]);
test('a typed array', new Uint32Array(3));
test('an array buffer', new ArrayBuffer(3));
test('a nested array', [[1, 2, 3]]);
test('true', true);
test('false', false);
test('an error', new Error());
test('a typed error with a message', new TypeError('message'));
/* eslint-disable no-new-func */
test('a function constructor', new Function());
/* eslint-enable no-new-func */
test('an anonymous function', () => {});
function named() {}
test('a named function', named);
test('Infinity', Infinity);
test('-Infinity', -Infinity);
test('an empty map', new Map());
const mapWithValues = new Map();
const mapWithNonStringKeys = new Map();
mapWithValues.set('prop1', 'value1');
mapWithValues.set('prop2', 'value2');
mapWithNonStringKeys.set({prop: 'value'}, {prop: 'value'});
test('a map with values', mapWithValues);
test('a map with non-string keys', mapWithNonStringKeys);
test('NaN', NaN);
test('null', null);
test('a number', 123);
test('a date', new Date(10e11));
test('an empty object', {});
test('an object with properties', {prop1: 'value1', prop2: 'value2'});
const objectWithPropsAndSymbols = {prop: 'value1'};
objectWithPropsAndSymbols[Symbol('symbol1')] = 'value2';
objectWithPropsAndSymbols[Symbol('symbol2')] = 'value3';
test('an object with properties and symbols', objectWithPropsAndSymbols);
test('an object with sorted properties', {a: 2, b: 1});
test('regular expressions from constructors', new RegExp('regexp'));
test('regular expressions from literals', /regexp/ig);
test('an empty set', new Set());
const setWithValues = new Set();
setWithValues.add('value1');
setWithValues.add('value2');
test('a set with values', setWithValues);
test('a string', 'string');
test('a symbol', Symbol('symbol'));
test('undefined', undefined);
test('a WeakMap', new WeakMap());
test('a WeakSet', new WeakSet());
test('deeply nested objects', {prop: {prop: {prop: 'value'}}});
const circularReferences = {};
circularReferences.prop = circularReferences;
test('circular references', circularReferences);
const parallelReferencesInner = {};
const parallelReferences = {
prop1: parallelReferencesInner,
prop2: parallelReferencesInner,
};
test('parallel references', parallelReferences);
test('able to customize indent', {prop: 'value'});
const bigObj = {};
for (let i = 0; i < 50; i++) {
bigObj[i] = i;
}
test('big object', bigObj);
const element = React.createElement(
'div',
{onClick: () => {}, prop: {a: 1, b: 2}},
React.createElement('div', {prop: {a: 1, b: 2}}),
React.createElement('div'),
React.createElement('div', {prop: {a: 1, b: 2}},
React.createElement('div', null,
React.createElement('div')
)
)
);
test('react', ReactTestRenderer.create(element).toJSON(), false, {
plugins: [ReactTestComponent],
});
TIMES_TO_RUN = 100;
test('massive', worldGeoJson, true);

File diff suppressed because one or more lines are too long