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,19 @@
'use strict'; /**
* Copyright (c) 2014, 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 chalk = require('chalk');
exports.NO_DIFF_MESSAGE = chalk.dim(
'Compared values have no visual difference.');
exports.SIMILAR_MESSAGE = chalk.dim(
'Compared values serialize to the same structure.\n' +
'Printing internal object structure without calling `toJSON` instead.');

View File

@@ -0,0 +1,152 @@
'use strict'; /**
* Copyright (c) 2014, 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 chalk = require('chalk');
var diff = require('diff');var _require =
require('./constants.js'),NO_DIFF_MESSAGE = _require.NO_DIFF_MESSAGE;
var DIFF_CONTEXT = 5;
var getColor = function getColor(added, removed) {return (
added ? chalk.red : removed ? chalk.green : chalk.dim);};
var getBgColor = function getBgColor(added, removed) {return (
added ? chalk.bgRed : removed ? chalk.bgGreen : chalk.dim);};
var highlightTrailingWhitespace = function highlightTrailingWhitespace(line, bgColor) {return (
line.replace(/\s+$/, bgColor('$&')));};
var getAnnotation = function getAnnotation(options) {return (
chalk.green('- ' + (options && options.aAnnotation || 'Expected')) +
'\n' +
chalk.red('+ ' + (options && options.bAnnotation || 'Received')) +
'\n\n');};
var diffLines = function diffLines(a, b) {
var isDifferent = false;
return {
diff: diff.
diffLines(a, b).
map(function (part) {var
added = part.added,removed = part.removed;
if (part.added || part.removed) {
isDifferent = true;
}
var lines = part.value.split('\n');
var color = getColor(added, removed);
var bgColor = getBgColor(added, removed);
if (lines[lines.length - 1] === '') {
lines.pop();
}
return lines.
map(function (line) {
var highlightedLine = highlightTrailingWhitespace(line, bgColor);
var mark = color(part.added ? '+' : part.removed ? '-' : ' ');
return mark + ' ' + color(highlightedLine) + '\n';
}).
join('');
}).
join('').
trim(),
isDifferent: isDifferent };
};
// Only show patch marks ("@@ ... @@") if the diff is big.
// To determine this, we need to compare either the original string (a) to
// `hunk.oldLines` or a new string to `hunk.newLines`.
// If the `oldLinesCount` is greater than `hunk.oldLines`
// we can be sure that at least 1 line has been "hidden".
var shouldShowPatchMarks = function shouldShowPatchMarks(hunk, oldLinesCount) {return (
oldLinesCount > hunk.oldLines);};
var createPatchMark = function createPatchMark(hunk) {
var markOld = '-' + hunk.oldStart + ',' + hunk.oldLines;
var markNew = '+' + hunk.newStart + ',' + hunk.newLines;
return chalk.yellow('@@ ' + markOld + ' ' + markNew + ' @@\n');
};
var structuredPatch = function structuredPatch(a, b) {
var options = { context: DIFF_CONTEXT };
var isDifferent = false;
// Make sure the strings end with a newline.
if (!a.endsWith('\n')) {
a += '\n';
}
if (!b.endsWith('\n')) {
b += '\n';
}
var oldLinesCount = (a.match(/\n/g) || []).length;
return {
diff: diff.
structuredPatch('', '', a, b, '', '', options).
hunks.map(function (hunk) {
var lines = hunk.lines.
map(function (line) {
var added = line[0] === '+';
var removed = line[0] === '-';
var color = getColor(added, removed);
var bgColor = getBgColor(added, removed);
var highlightedLine = highlightTrailingWhitespace(line, bgColor);
return color(highlightedLine) + '\n';
}).
join('');
isDifferent = true;
return shouldShowPatchMarks(hunk, oldLinesCount) ?
createPatchMark(hunk) + lines :
lines;
}).
join('').
trim(),
isDifferent: isDifferent };
};
function diffStrings(a, b, options) {
// `diff` uses the Myers LCS diff algorithm which runs in O(n+d^2) time
// (where "d" is the edit distance) and can get very slow for large edit
// distances. Mitigate the cost by switching to a lower-resolution diff
// whenever linebreaks are involved.
var result = options && options.expand === false ?
structuredPatch(a, b) :
diffLines(a, b);
if (result.isDifferent) {
return getAnnotation(options) + result.diff;
} else {
return NO_DIFF_MESSAGE;
}
}
module.exports = diffStrings;

View File

@@ -0,0 +1,137 @@
'use strict';var _set = require('babel-runtime/core-js/set');var _set2 = _interopRequireDefault(_set);var _from = require('babel-runtime/core-js/array/from');var _from2 = _interopRequireDefault(_from);var _map = require('babel-runtime/core-js/map');var _map2 = _interopRequireDefault(_map);var _for = require('babel-runtime/core-js/symbol/for');var _for2 = _interopRequireDefault(_for);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var _require$plugins =
require('pretty-format').plugins,ReactElement = _require$plugins.ReactElement,ReactTestComponent = _require$plugins.ReactTestComponent,AsymmetricMatcher = _require$plugins.AsymmetricMatcher,HTMLElement = _require$plugins.HTMLElement,Immutable = _require$plugins.Immutable; /**
* Copyright (c) 2014, 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 chalk = require('chalk');var _require = require('jest-matcher-utils'),getType = _require.getType;var prettyFormat = require('pretty-format');var diffStrings = require('./diffStrings');var _require2 = require('./constants'),NO_DIFF_MESSAGE = _require2.NO_DIFF_MESSAGE,SIMILAR_MESSAGE = _require2.SIMILAR_MESSAGE;
var PLUGINS = [
ReactTestComponent,
ReactElement,
AsymmetricMatcher,
HTMLElement].
concat(Immutable);
var FORMAT_OPTIONS = {
plugins: PLUGINS };
var FALLBACK_FORMAT_OPTIONS = {
callToJSON: false,
maxDepth: 10,
plugins: PLUGINS };
// Generate a string that will highlight the difference between two values
// with green and red. (similar to how github does code diffing)
function diff(a, b, options) {
if (a === b) {
return NO_DIFF_MESSAGE;
}
var aType = getType(a);
var expectedType = aType;
var omitDifference = false;
if (aType === 'object' && typeof a.asymmetricMatch === 'function') {
if (a.$$typeof !== (0, _for2.default)('jest.asymmetricMatcher')) {
// Do not know expected type of user-defined asymmetric matcher.
return null;
}
if (typeof a.getExpectedType !== 'function') {
// For example, expect.anything() matches either null or undefined
return null;
}
expectedType = a.getExpectedType();
// Primitive types boolean and number omit difference below.
// For example, omit difference for expect.stringMatching(regexp)
omitDifference = expectedType === 'string';
}
if (expectedType !== getType(b)) {
return (
' Comparing two different types of values.' + (' Expected ' +
chalk.green(expectedType) + ' but ') + ('received ' +
chalk.red(getType(b)) + '.'));
}
if (omitDifference) {
return null;
}
switch (aType) {
case 'string':
var multiline = a.match(/[\r\n]/) !== -1 && b.indexOf('\n') !== -1;
if (multiline) {
return diffStrings(String(a), String(b), options);
}
return null;
case 'number':
case 'boolean':
return null;
case 'map':
return compareObjects(sortMap(a), sortMap(b), options);
case 'set':
return compareObjects(sortSet(a), sortSet(b), options);
default:
return compareObjects(a, b, options);}
}
function sortMap(map) {
return new _map2.default((0, _from2.default)(map.entries()).sort());
}
function sortSet(set) {
return new _set2.default((0, _from2.default)(set.values()).sort());
}
function compareObjects(a, b, options) {
var diffMessage = void 0;
var hasThrown = false;
try {
diffMessage = diffStrings(
prettyFormat(a, FORMAT_OPTIONS),
prettyFormat(b, FORMAT_OPTIONS),
options);
} catch (e) {
hasThrown = true;
}
// If the comparison yields no results, compare again but this time
// without calling `toJSON`. It's also possible that toJSON might throw.
if (!diffMessage || diffMessage === NO_DIFF_MESSAGE) {
diffMessage = diffStrings(
prettyFormat(a, FALLBACK_FORMAT_OPTIONS),
prettyFormat(b, FALLBACK_FORMAT_OPTIONS),
options);
if (diffMessage !== NO_DIFF_MESSAGE && !hasThrown) {
diffMessage = SIMILAR_MESSAGE + '\n\n' + diffMessage;
}
}
return diffMessage;
}
module.exports = diff;

View File

@@ -0,0 +1,19 @@
'use strict'; /**
* Copyright (c) 2014, 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 chalk = require('chalk');
exports.NO_DIFF_MESSAGE = chalk.dim(
'Compared values have no visual difference.');
exports.SIMILAR_MESSAGE = chalk.dim(
'Compared values serialize to the same structure.\n' +
'Printing internal object structure without calling `toJSON` instead.');

View File

@@ -0,0 +1,152 @@
'use strict'; /**
* Copyright (c) 2014, 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 chalk = require('chalk');
const diff = require('diff');var _require =
require('./constants.js');const NO_DIFF_MESSAGE = _require.NO_DIFF_MESSAGE;
const DIFF_CONTEXT = 5;
const getColor = (added, removed) =>
added ? chalk.red : removed ? chalk.green : chalk.dim;
const getBgColor = (added, removed) =>
added ? chalk.bgRed : removed ? chalk.bgGreen : chalk.dim;
const highlightTrailingWhitespace = (line, bgColor) =>
line.replace(/\s+$/, bgColor('$&'));
const getAnnotation = options =>
chalk.green('- ' + (options && options.aAnnotation || 'Expected')) +
'\n' +
chalk.red('+ ' + (options && options.bAnnotation || 'Received')) +
'\n\n';
const diffLines = (a, b) => {
let isDifferent = false;
return {
diff: diff.
diffLines(a, b).
map(part => {const
added = part.added,removed = part.removed;
if (part.added || part.removed) {
isDifferent = true;
}
const lines = part.value.split('\n');
const color = getColor(added, removed);
const bgColor = getBgColor(added, removed);
if (lines[lines.length - 1] === '') {
lines.pop();
}
return lines.
map(line => {
const highlightedLine = highlightTrailingWhitespace(line, bgColor);
const mark = color(part.added ? '+' : part.removed ? '-' : ' ');
return mark + ' ' + color(highlightedLine) + '\n';
}).
join('');
}).
join('').
trim(),
isDifferent };
};
// Only show patch marks ("@@ ... @@") if the diff is big.
// To determine this, we need to compare either the original string (a) to
// `hunk.oldLines` or a new string to `hunk.newLines`.
// If the `oldLinesCount` is greater than `hunk.oldLines`
// we can be sure that at least 1 line has been "hidden".
const shouldShowPatchMarks = (hunk, oldLinesCount) =>
oldLinesCount > hunk.oldLines;
const createPatchMark = hunk => {
const markOld = `-${hunk.oldStart},${hunk.oldLines}`;
const markNew = `+${hunk.newStart},${hunk.newLines}`;
return chalk.yellow(`@@ ${markOld} ${markNew} @@\n`);
};
const structuredPatch = (a, b) => {
const options = { context: DIFF_CONTEXT };
let isDifferent = false;
// Make sure the strings end with a newline.
if (!a.endsWith('\n')) {
a += '\n';
}
if (!b.endsWith('\n')) {
b += '\n';
}
const oldLinesCount = (a.match(/\n/g) || []).length;
return {
diff: diff.
structuredPatch('', '', a, b, '', '', options).
hunks.map(hunk => {
const lines = hunk.lines.
map(line => {
const added = line[0] === '+';
const removed = line[0] === '-';
const color = getColor(added, removed);
const bgColor = getBgColor(added, removed);
const highlightedLine = highlightTrailingWhitespace(line, bgColor);
return color(highlightedLine) + '\n';
}).
join('');
isDifferent = true;
return shouldShowPatchMarks(hunk, oldLinesCount) ?
createPatchMark(hunk) + lines :
lines;
}).
join('').
trim(),
isDifferent };
};
function diffStrings(a, b, options) {
// `diff` uses the Myers LCS diff algorithm which runs in O(n+d^2) time
// (where "d" is the edit distance) and can get very slow for large edit
// distances. Mitigate the cost by switching to a lower-resolution diff
// whenever linebreaks are involved.
const result = options && options.expand === false ?
structuredPatch(a, b) :
diffLines(a, b);
if (result.isDifferent) {
return getAnnotation(options) + result.diff;
} else {
return NO_DIFF_MESSAGE;
}
}
module.exports = diffStrings;

View File

@@ -0,0 +1,137 @@
'use strict';var _require$plugins =
require('pretty-format').plugins;const ReactElement = _require$plugins.ReactElement,ReactTestComponent = _require$plugins.ReactTestComponent,AsymmetricMatcher = _require$plugins.AsymmetricMatcher,HTMLElement = _require$plugins.HTMLElement,Immutable = _require$plugins.Immutable; /**
* Copyright (c) 2014, 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 chalk = require('chalk');var _require = require('jest-matcher-utils');const getType = _require.getType;const prettyFormat = require('pretty-format');const diffStrings = require('./diffStrings');var _require2 = require('./constants');const NO_DIFF_MESSAGE = _require2.NO_DIFF_MESSAGE,SIMILAR_MESSAGE = _require2.SIMILAR_MESSAGE;
const PLUGINS = [
ReactTestComponent,
ReactElement,
AsymmetricMatcher,
HTMLElement].
concat(Immutable);
const FORMAT_OPTIONS = {
plugins: PLUGINS };
const FALLBACK_FORMAT_OPTIONS = {
callToJSON: false,
maxDepth: 10,
plugins: PLUGINS };
// Generate a string that will highlight the difference between two values
// with green and red. (similar to how github does code diffing)
function diff(a, b, options) {
if (a === b) {
return NO_DIFF_MESSAGE;
}
const aType = getType(a);
let expectedType = aType;
let omitDifference = false;
if (aType === 'object' && typeof a.asymmetricMatch === 'function') {
if (a.$$typeof !== Symbol.for('jest.asymmetricMatcher')) {
// Do not know expected type of user-defined asymmetric matcher.
return null;
}
if (typeof a.getExpectedType !== 'function') {
// For example, expect.anything() matches either null or undefined
return null;
}
expectedType = a.getExpectedType();
// Primitive types boolean and number omit difference below.
// For example, omit difference for expect.stringMatching(regexp)
omitDifference = expectedType === 'string';
}
if (expectedType !== getType(b)) {
return (
' Comparing two different types of values.' +
` Expected ${chalk.green(expectedType)} but ` +
`received ${chalk.red(getType(b))}.`);
}
if (omitDifference) {
return null;
}
switch (aType) {
case 'string':
const multiline = a.match(/[\r\n]/) !== -1 && b.indexOf('\n') !== -1;
if (multiline) {
return diffStrings(String(a), String(b), options);
}
return null;
case 'number':
case 'boolean':
return null;
case 'map':
return compareObjects(sortMap(a), sortMap(b), options);
case 'set':
return compareObjects(sortSet(a), sortSet(b), options);
default:
return compareObjects(a, b, options);}
}
function sortMap(map) {
return new Map(Array.from(map.entries()).sort());
}
function sortSet(set) {
return new Set(Array.from(set.values()).sort());
}
function compareObjects(a, b, options) {
let diffMessage;
let hasThrown = false;
try {
diffMessage = diffStrings(
prettyFormat(a, FORMAT_OPTIONS),
prettyFormat(b, FORMAT_OPTIONS),
options);
} catch (e) {
hasThrown = true;
}
// If the comparison yields no results, compare again but this time
// without calling `toJSON`. It's also possible that toJSON might throw.
if (!diffMessage || diffMessage === NO_DIFF_MESSAGE) {
diffMessage = diffStrings(
prettyFormat(a, FALLBACK_FORMAT_OPTIONS),
prettyFormat(b, FALLBACK_FORMAT_OPTIONS),
options);
if (diffMessage !== NO_DIFF_MESSAGE && !hasThrown) {
diffMessage = SIMILAR_MESSAGE + '\n\n' + diffMessage;
}
}
return diffMessage;
}
module.exports = diff;

View File

@@ -0,0 +1,51 @@
{
"_args": [
[
"jest-diff@20.0.3",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "jest-diff@20.0.3",
"_id": "jest-diff@20.0.3",
"_inBundle": false,
"_integrity": "sha1-gfKI/Z5nXw+yPHXxwrGURf5YZhc=",
"_location": "/react-scripts/jest-diff",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "jest-diff@20.0.3",
"name": "jest-diff",
"escapedName": "jest-diff",
"rawSpec": "20.0.3",
"saveSpec": null,
"fetchSpec": "20.0.3"
},
"_requiredBy": [
"/react-scripts/jest-jasmine2",
"/react-scripts/jest-matchers",
"/react-scripts/jest-snapshot"
],
"_resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-20.0.3.tgz",
"_spec": "20.0.3",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"browser": "build-es5/index.js",
"bugs": {
"url": "https://github.com/facebook/jest/issues"
},
"dependencies": {
"chalk": "^1.1.3",
"diff": "^3.2.0",
"jest-matcher-utils": "^20.0.3",
"pretty-format": "^20.0.3"
},
"homepage": "https://github.com/facebook/jest#readme",
"license": "BSD-3-Clause",
"main": "build/index.js",
"name": "jest-diff",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/jest.git"
},
"version": "20.0.3"
}