unexpected
Advanced tools
Comparing version 11.1.2 to 11.2.0
function addAdditionalPromiseMethods(promise, expect, subject) { | ||
promise.and = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
promise.and = function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
@@ -11,3 +10,3 @@ function executeAnd() { | ||
} else { | ||
return expect.apply(undefined, [subject].concat(args)); | ||
return expect.apply(void 0, [ subject ].concat( args )); | ||
} | ||
@@ -19,3 +18,7 @@ } | ||
} else { | ||
return addAdditionalPromiseMethods(this.then(executeAnd), expect, subject); | ||
return addAdditionalPromiseMethods( | ||
this.then(executeAnd), | ||
expect, | ||
subject | ||
); | ||
} | ||
@@ -27,2 +30,2 @@ }; | ||
module.exports = addAdditionalPromiseMethods; | ||
module.exports = addAdditionalPromiseMethods; |
module.exports = function AssertionString(text) { | ||
this.text = text; | ||
}; | ||
}; |
@@ -1,30 +0,12 @@ | ||
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); | ||
var Context = function Context(expect) { | ||
this.expect = expect; | ||
this.level = 0; | ||
}; | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
Context.prototype.child = function child () { | ||
var child = Object.create(this); | ||
child.level++; | ||
return child; | ||
}; | ||
var _createClass2 = require("babel-runtime/helpers/createClass"); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Context = function () { | ||
function Context(expect) { | ||
(0, _classCallCheck3.default)(this, Context); | ||
this.expect = expect; | ||
this.level = 0; | ||
} | ||
(0, _createClass3.default)(Context, [{ | ||
key: "child", | ||
value: function child() { | ||
var child = Object.create(this); | ||
child.level++; | ||
return child; | ||
} | ||
}]); | ||
return Context; | ||
}(); | ||
module.exports = Context; | ||
module.exports = Context; |
@@ -1,11 +0,11 @@ | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var AssertionString = require('./AssertionString'); | ||
module.exports = function createStandardErrorMessage(output, subject, testDescription, args) { | ||
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; | ||
module.exports = function createStandardErrorMessage( | ||
output, | ||
subject, | ||
testDescription, | ||
args, | ||
options | ||
) { | ||
if ( options === void 0 ) options = {}; | ||
@@ -26,3 +26,4 @@ var preamble = 'expected'; | ||
args.forEach(function (arg, index) { | ||
var isAssertion = arg && (typeof arg === 'undefined' ? 'undefined' : (0, _typeof3.default)(arg)) === 'object' && arg instanceof AssertionString; | ||
var isAssertion = | ||
arg && typeof arg === 'object' && arg instanceof AssertionString; | ||
if (index > 0) { | ||
@@ -46,3 +47,7 @@ if (!isAssertion && !previousWasAssertion) { | ||
var argsSize = argsOutput.size(); | ||
var width = preamble.length + subjectSize.width + argsSize.width + testDescription.length; | ||
var width = | ||
preamble.length + | ||
subjectSize.width + | ||
argsSize.width + | ||
testDescription.length; | ||
var height = Math.max(subjectSize.height, argsSize.height); | ||
@@ -59,5 +64,9 @@ | ||
} else { | ||
testDescription = 'expected: ' + testDescription; | ||
testDescription = "expected: " + testDescription; | ||
} | ||
} else if (options.compact && options.compactSubject && (subjectSize.height > 1 || subjectSize.width > (options.compactWidth || 35))) { | ||
} else if ( | ||
options.compact && | ||
options.compactSubject && | ||
(subjectSize.height > 1 || subjectSize.width > (options.compactWidth || 35)) | ||
) { | ||
output.error('expected').sp(); | ||
@@ -74,3 +83,6 @@ options.compactSubject.call(output, output); | ||
output.append(subjectOutput); | ||
if (subjectSize.height > 1 || height === 1 && width > output.preferredWidth) { | ||
if ( | ||
subjectSize.height > 1 || | ||
(height === 1 && width > output.preferredWidth) | ||
) { | ||
output.nl(); | ||
@@ -93,2 +105,2 @@ } else { | ||
return output; | ||
}; | ||
}; |
@@ -1,11 +0,1 @@ | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var createStandardErrorMessage = require('./createStandardErrorMessage'); | ||
@@ -30,4 +20,4 @@ var utils = require('./utils'); | ||
function isAssertionArg(_ref) { | ||
var type = _ref.type; | ||
function isAssertionArg(ref) { | ||
var type = ref.type; | ||
@@ -44,3 +34,2 @@ return type.is('assertion'); | ||
}, | ||
equal: utils.objectIs, | ||
@@ -52,12 +41,11 @@ inspect: function inspect(value, depth, output) { | ||
// Guard against node.js' require('util').inspect eagerly calling .inspect() on objects | ||
return 'type: ' + this.name; | ||
return ("type: " + (this.name)); | ||
} | ||
}, | ||
diff: function diff(actual, expected, output, _diff, inspect) { | ||
diff: function diff(actual, expected, output, diff$1, inspect) { | ||
return null; | ||
}, | ||
typeEqualityCache: {}, | ||
is: function is(typeOrTypeName) { | ||
var typeName = void 0; | ||
var typeName; | ||
if (typeof typeOrTypeName === 'string') { | ||
@@ -86,4 +74,4 @@ typeName = typeOrTypeName; | ||
if (nodeJsCustomInspect !== 'inspect') { | ||
anyType[nodeJsCustomInspect] = function () { | ||
return 'type: ' + this.name; | ||
anyType[nodeJsCustomInspect] = function() { | ||
return ("type: " + (this.name)); | ||
}; | ||
@@ -114,3 +102,5 @@ } | ||
if (args.length > 2) { | ||
throw new Error('expect.it(<function>) does not accept additional arguments'); | ||
throw new Error( | ||
'expect.it(<function>) does not accept additional arguments' | ||
); | ||
} else { | ||
@@ -130,4 +120,5 @@ // expect.it(function (value) { ... }) | ||
var hasOrClauses = groupEvaluations.length > 1; | ||
var hasAndClauses = groupEvaluations.some(function (_ref2) { | ||
var length = _ref2.length; | ||
var hasAndClauses = groupEvaluations.some(function (ref) { | ||
var length = ref.length; | ||
return length > 1; | ||
@@ -172,15 +163,19 @@ }); | ||
var subject = expectation[0]; | ||
var subjectOutput = function subjectOutput(output) { | ||
var subjectOutput = function (output) { | ||
output.appendInspected(subject); | ||
}; | ||
var args = expectation.slice(2); | ||
var argsOutput = args.map(function (arg) { | ||
return function (output) { | ||
output.appendInspected(arg); | ||
}; | ||
}); | ||
var argsOutput = args.map(function (arg) { return function (output) { | ||
output.appendInspected(arg); | ||
}; }); | ||
var testDescription = expectation[1]; | ||
createStandardErrorMessage(output, subjectOutput, testDescription, argsOutput, { | ||
subject: subject | ||
}); | ||
createStandardErrorMessage( | ||
output, | ||
subjectOutput, | ||
testDescription, | ||
argsOutput, | ||
{ | ||
subject: subject | ||
} | ||
); | ||
}); | ||
@@ -196,5 +191,13 @@ } | ||
function expectIt(subject, context) { | ||
context = context && (typeof context === 'undefined' ? 'undefined' : (0, _typeof3.default)(context)) === 'object' && context instanceof Context ? context : new Context(expect); | ||
context = | ||
context && typeof context === 'object' && context instanceof Context | ||
? context | ||
: new Context(expect); | ||
if (orGroups.length === 1 && orGroups[0].length === 1 && orGroups[0][0].length === 1 && typeof orGroups[0][0][0] === 'function') { | ||
if ( | ||
orGroups.length === 1 && | ||
orGroups[0].length === 1 && | ||
orGroups[0][0].length === 1 && | ||
typeof orGroups[0][0][0] === 'function' | ||
) { | ||
// expect.it(subject => ...) | ||
@@ -208,4 +211,4 @@ return oathbreaker(orGroups[0][0][0](subject)); | ||
var evaluations = evaluateGroup(expect, context, subject, orGroup); | ||
evaluations.forEach(function (_ref3) { | ||
var promise = _ref3.promise; | ||
evaluations.forEach(function (ref) { | ||
var promise = ref.promise; | ||
@@ -217,24 +220,31 @@ promises.push(promise); | ||
return oathbreaker(makePromise.settle(promises).then(function () { | ||
groupEvaluations.forEach(function (groupEvaluation) { | ||
groupEvaluation.forEach(function (_ref4) { | ||
var promise = _ref4.promise; | ||
return oathbreaker( | ||
makePromise.settle(promises).then(function () { | ||
groupEvaluations.forEach(function (groupEvaluation) { | ||
groupEvaluation.forEach(function (ref) { | ||
var promise = ref.promise; | ||
if (promise.isRejected() && promise.reason().errorMode === 'bubbleThrough') { | ||
throw promise.reason(); | ||
} | ||
if ( | ||
promise.isRejected() && | ||
promise.reason().errorMode === 'bubbleThrough' | ||
) { | ||
throw promise.reason(); | ||
} | ||
}); | ||
}); | ||
}); | ||
if (!groupEvaluations.some(function (groupEvaluation) { | ||
return groupEvaluation.every(function (_ref5) { | ||
var promise = _ref5.promise; | ||
return promise.isFulfilled(); | ||
}); | ||
})) { | ||
expect.fail(function (output) { | ||
writeGroupEvaluationsToOutput(output, groupEvaluations); | ||
}); | ||
} | ||
})); | ||
if ( | ||
!groupEvaluations.some(function (groupEvaluation) { return groupEvaluation.every(function (ref) { | ||
var promise = ref.promise; | ||
return promise.isFulfilled(); | ||
}); } | ||
) | ||
) { | ||
expect.fail(function (output) { | ||
writeGroupEvaluationsToOutput(output, groupEvaluations); | ||
}); | ||
} | ||
}) | ||
); | ||
} | ||
@@ -244,19 +254,15 @@ expectIt._expectIt = true; | ||
expectIt._OR = OR; | ||
expectIt.and = function () { | ||
expectIt.and = function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var copiedExpectations = expectations.slice(); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
copiedExpectations.push(args); | ||
return createExpectIt(expect, copiedExpectations); | ||
}; | ||
expectIt.or = function () { | ||
expectIt.or = function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var copiedExpectations = expectations.slice(); | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
copiedExpectations.push(OR, args); | ||
@@ -275,6 +281,5 @@ return createExpectIt(expect, copiedExpectations); | ||
expectPrototype.it = function () { | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
expectPrototype.it = function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
@@ -287,4 +292,4 @@ if (this.flags && typeof args[0] === 'string') { | ||
expectPrototype.equal = function (actual, expected, depth, seen) { | ||
var _this = this; | ||
expectPrototype.equal = function(actual, expected, depth, seen) { | ||
var this$1 = this; | ||
@@ -301,13 +306,12 @@ depth = typeof depth === 'number' ? depth : 100; | ||
return this.findCommonType(actual, expected).equal(actual, expected, function (a, b) { | ||
return _this.equal(a, b, depth - 1, seen); | ||
}); | ||
return this.findCommonType(actual, expected).equal(actual, expected, function (a, b) { return this$1.equal(a, b, depth - 1, seen); } | ||
); | ||
}; | ||
expectPrototype.inspect = function (obj, depth, outputOrFormat) { | ||
var _this2 = this; | ||
expectPrototype.inspect = function(obj, depth, outputOrFormat) { | ||
var this$1 = this; | ||
var seen = []; | ||
var printOutput = function printOutput(obj, currentDepth, output) { | ||
var objType = _this2.findTypeOf(obj); | ||
var printOutput = function (obj, currentDepth, output) { | ||
var objType = this$1.findTypeOf(obj); | ||
if (currentDepth <= 0 && objType.is('object') && !objType.is('expect.it')) { | ||
@@ -334,5 +338,14 @@ return output.text('...'); | ||
var output = typeof outputOrFormat === 'string' ? this.createOutput(outputOrFormat) : outputOrFormat; | ||
var output = | ||
typeof outputOrFormat === 'string' | ||
? this.createOutput(outputOrFormat) | ||
: outputOrFormat; | ||
output = output || this.createOutput(); | ||
return printOutput(obj, typeof depth === 'number' ? depth : defaultDepth, output) || output; | ||
return ( | ||
printOutput( | ||
obj, | ||
typeof depth === 'number' ? depth : defaultDepth, | ||
output | ||
) || output | ||
); | ||
}; | ||
@@ -344,6 +357,6 @@ | ||
expectPrototype.expandTypeAlternations = function (assertion) { | ||
var _this3 = this; | ||
expectPrototype.expandTypeAlternations = function(assertion) { | ||
var this$1 = this; | ||
var createPermutations = function createPermutations(args, i) { | ||
var createPermutations = function (args, i) { | ||
if (i === args.length) { | ||
@@ -361,4 +374,9 @@ return []; | ||
} else if (arg.type.is('assertion')) { | ||
result.push([{ type: arg.type, minimum: 1, maximum: 1 }, { type: _this3.getType('any'), minimum: 0, maximum: Infinity }]); | ||
result.push([{ type: _this3.getType('expect.it'), minimum: 1, maximum: 1 }]); | ||
result.push([ | ||
{ type: arg.type, minimum: 1, maximum: 1 }, | ||
{ type: this$1.getType('any'), minimum: 0, maximum: Infinity } | ||
]); | ||
result.push([ | ||
{ type: this$1.getType('expect.it'), minimum: 1, maximum: 1 } | ||
]); | ||
if (arg.minimum === 0) { | ||
@@ -378,12 +396,16 @@ // <assertion?> | ||
createPermutations(assertion.args, 0).forEach(function (args) { | ||
result.push(extend({}, assertion, { | ||
subject: subjectRequirement, | ||
args: args | ||
})); | ||
result.push( | ||
extend({}, assertion, { | ||
subject: subjectRequirement, | ||
args: args | ||
}) | ||
); | ||
}); | ||
} else { | ||
result.push(extend({}, assertion, { | ||
subject: subjectRequirement, | ||
args: [] | ||
})); | ||
result.push( | ||
extend({}, assertion, { | ||
subject: subjectRequirement, | ||
args: [] | ||
}) | ||
); | ||
} | ||
@@ -394,4 +416,4 @@ }); | ||
expectPrototype.parseAssertion = function (assertionString) { | ||
var _this4 = this; | ||
expectPrototype.parseAssertion = function(assertionString) { | ||
var this$1 = this; | ||
@@ -401,11 +423,17 @@ var tokens = []; | ||
var parseTypeToken = function parseTypeToken(typeToken) { | ||
var parseTypeToken = function (typeToken) { | ||
return typeToken.split('|').map(function (typeDeclaration) { | ||
var matchNameAndOperator = typeDeclaration.match(/^([a-z_](?:|[a-z0-9_.-]*[_a-z0-9]))([+*?]|)$/i); | ||
var matchNameAndOperator = typeDeclaration.match( | ||
/^([a-z_](?:|[a-z0-9_.-]*[_a-z0-9]))([+*?]|)$/i | ||
); | ||
if (!matchNameAndOperator) { | ||
throw new SyntaxError('Cannot parse type declaration:' + typeDeclaration); | ||
throw new SyntaxError( | ||
("Cannot parse type declaration:" + typeDeclaration) | ||
); | ||
} | ||
var type = _this4.getType(matchNameAndOperator[1]); | ||
var type = this$1.getType(matchNameAndOperator[1]); | ||
if (!type) { | ||
throw new Error('Unknown type: ' + matchNameAndOperator[1] + ' in ' + assertionString); | ||
throw new Error( | ||
("Unknown type: " + (matchNameAndOperator[1]) + " in " + assertionString) | ||
); | ||
} | ||
@@ -422,26 +450,35 @@ var operator = matchNameAndOperator[2]; | ||
function hasVarargs(types) { | ||
return types.some(function (_ref6) { | ||
var minimum = _ref6.minimum, | ||
maximum = _ref6.maximum; | ||
return types.some(function (ref) { | ||
var minimum = ref.minimum; | ||
var maximum = ref.maximum; | ||
return minimum !== 1 || maximum !== 1; | ||
}); | ||
} | ||
assertionString.replace(/\s*<((?:[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])[?*+]?)(?:\|(?:[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])[?*+]?))*)>|\s*([^<]+)/gi, function (_ref7, $1, $2, index) { | ||
var length = _ref7.length; | ||
assertionString.replace( | ||
/\s*<((?:[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])[?*+]?)(?:\|(?:[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])[?*+]?))*)>|\s*([^<]+)/gi, | ||
function (ref, $1, $2, index) { | ||
var length = ref.length; | ||
if (index !== nextIndex) { | ||
throw new SyntaxError('Cannot parse token at index ' + nextIndex + ' in ' + assertionString); | ||
if (index !== nextIndex) { | ||
throw new SyntaxError( | ||
("Cannot parse token at index " + nextIndex + " in " + assertionString) | ||
); | ||
} | ||
if ($1) { | ||
tokens.push(parseTypeToken($1)); | ||
} else { | ||
tokens.push($2.trim()); | ||
} | ||
nextIndex += length; | ||
} | ||
if ($1) { | ||
tokens.push(parseTypeToken($1)); | ||
} else { | ||
tokens.push($2.trim()); | ||
} | ||
nextIndex += length; | ||
}); | ||
); | ||
var assertion = void 0; | ||
var assertion; | ||
if (tokens.length === 1 && typeof tokens[0] === 'string') { | ||
if (!this._legacyTypelessAssertionWarned) { | ||
console.warn('The typeless expect.addAssertion syntax is deprecated and will be removed in a future update\n' + 'Please refer to http://unexpected.js.org/api/addAssertion/'); | ||
console.warn( | ||
'The typeless expect.addAssertion syntax is deprecated and will be removed in a future update\n' + | ||
'Please refer to http://unexpected.js.org/api/addAssertion/' | ||
); | ||
this._legacyTypelessAssertionWarned = true; | ||
@@ -463,13 +500,13 @@ } | ||
if (!Array.isArray(assertion.subject)) { | ||
throw new SyntaxError('Missing subject type in ' + assertionString); | ||
throw new SyntaxError(("Missing subject type in " + assertionString)); | ||
} | ||
if (typeof assertion.assertion !== 'string') { | ||
throw new SyntaxError('Missing assertion in ' + assertionString); | ||
throw new SyntaxError(("Missing assertion in " + assertionString)); | ||
} | ||
if (hasVarargs(assertion.subject)) { | ||
throw new SyntaxError('The subject type cannot have varargs: ' + assertionString); | ||
throw new SyntaxError( | ||
("The subject type cannot have varargs: " + assertionString) | ||
); | ||
} | ||
if (assertion.args.some(function (arg) { | ||
return typeof arg === 'string'; | ||
})) { | ||
if (assertion.args.some(function (arg) { return typeof arg === 'string'; })) { | ||
throw new SyntaxError('Only one assertion string is supported (see #225)'); | ||
@@ -479,28 +516,43 @@ } | ||
if (assertion.args.slice(0, -1).some(hasVarargs)) { | ||
throw new SyntaxError('Only the last argument type can have varargs: ' + assertionString); | ||
throw new SyntaxError( | ||
("Only the last argument type can have varargs: " + assertionString) | ||
); | ||
} | ||
if ([assertion.subject].concat(assertion.args.slice(0, -1)).some(function (argRequirements) { | ||
return argRequirements.some(function (_ref8) { | ||
var type = _ref8.type; | ||
return type.is('assertion'); | ||
}); | ||
})) { | ||
throw new SyntaxError('Only the last argument type can be <assertion>: ' + assertionString); | ||
if ( | ||
[assertion.subject] | ||
.concat(assertion.args.slice(0, -1)) | ||
.some(function (argRequirements) { return argRequirements.some(function (ref) { | ||
var type = ref.type; | ||
return type.is('assertion'); | ||
}); } | ||
) | ||
) { | ||
throw new SyntaxError( | ||
("Only the last argument type can be <assertion>: " + assertionString) | ||
); | ||
} | ||
var lastArgRequirements = assertion.args[assertion.args.length - 1] || []; | ||
var assertionRequirements = lastArgRequirements.filter(function (_ref9) { | ||
var type = _ref9.type; | ||
return type.is('assertion'); | ||
}); | ||
var assertionRequirements = lastArgRequirements.filter(function (ref) { | ||
var type = ref.type; | ||
return type.is('assertion'); | ||
} | ||
); | ||
if (assertionRequirements.length > 0 && lastArgRequirements.length > 1) { | ||
throw new SyntaxError('<assertion> cannot be alternated with other types: ' + assertionString); | ||
throw new SyntaxError( | ||
("<assertion> cannot be alternated with other types: " + assertionString) | ||
); | ||
} | ||
if (assertionRequirements.some(function (_ref10) { | ||
var maximum = _ref10.maximum; | ||
if (assertionRequirements.some(function (ref) { | ||
var maximum = ref.maximum; | ||
return maximum !== 1; | ||
})) { | ||
throw new SyntaxError('<assertion+> and <assertion*> are not allowed: ' + assertionString); | ||
throw new SyntaxError( | ||
("<assertion+> and <assertion*> are not allowed: " + assertionString) | ||
); | ||
} | ||
@@ -512,3 +564,5 @@ return this.expandTypeAlternations(assertion); | ||
var placeholderRegexp = /\{(\d+)\}/; | ||
expectPrototype._fail = function (arg) { | ||
expectPrototype._fail = function(arg) { | ||
var arguments$1 = arguments; | ||
if (arg instanceof UnexpectedError) { | ||
@@ -527,3 +581,3 @@ arg._hasSerializedErrorMessage = false; | ||
error.output = arg; | ||
} else if (arg && (typeof arg === 'undefined' ? 'undefined' : (0, _typeof3.default)(arg)) === 'object') { | ||
} else if (arg && typeof arg === 'object') { | ||
if (typeof arg.message !== 'undefined') { | ||
@@ -545,4 +599,4 @@ error.errorMode = 'bubble'; | ||
}; | ||
Object.keys(arg).forEach(function (key) { | ||
var _this5 = this; | ||
Object.keys(arg).forEach(function(key) { | ||
var this$1 = this; | ||
@@ -553,12 +607,15 @@ var value = arg[key]; | ||
error.createDiff = function (output, diff, inspect, equal) { | ||
var childOutput = _this5.createOutput(output.format); | ||
var childOutput = this$1.createOutput(output.format); | ||
childOutput.inline = output.inline; | ||
childOutput.output = output.output; | ||
return value(childOutput, function (actual, expected) { | ||
return _this5.diff(actual, expected, childOutput.clone()); | ||
}, function (v, depth) { | ||
return childOutput.clone().appendInspected(v, (depth || defaultDepth) - 1); | ||
}, function (actual, expected) { | ||
return _this5.equal(actual, expected); | ||
}); | ||
return value( | ||
childOutput, | ||
function (actual, expected) { | ||
return this$1.diff(actual, expected, childOutput.clone()); | ||
}, | ||
function (v, depth) { return childOutput | ||
.clone() | ||
.appendInspected(v, (depth || defaultDepth) - 1); }, | ||
function (actual, expected) { return this$1.equal(actual, expected); } | ||
); | ||
}; | ||
@@ -573,7 +630,7 @@ } else { | ||
} else { | ||
var placeholderArgs = void 0; | ||
var placeholderArgs; | ||
if (arguments.length > 0) { | ||
placeholderArgs = new Array(arguments.length - 1); | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
placeholderArgs[i - 1] = arguments[i]; | ||
placeholderArgs[i - 1] = arguments$1[i]; | ||
} | ||
@@ -619,23 +676,31 @@ } | ||
function calculateAssertionSpecificity(_ref11) { | ||
var subject = _ref11.subject, | ||
args = _ref11.args; | ||
function calculateAssertionSpecificity(ref) { | ||
var subject = ref.subject; | ||
var args = ref.args; | ||
return [subject.type.level].concat(args.map(function (_ref12) { | ||
var minimum = _ref12.minimum, | ||
maximum = _ref12.maximum, | ||
type = _ref12.type; | ||
return [subject.type.level].concat( | ||
args.map(function (ref) { | ||
var minimum = ref.minimum; | ||
var maximum = ref.maximum; | ||
var type = ref.type; | ||
var bonus = minimum === 1 && maximum === 1 ? 0.5 : 0; | ||
return bonus + type.level; | ||
})); | ||
var bonus = minimum === 1 && maximum === 1 ? 0.5 : 0; | ||
return bonus + type.level; | ||
}) | ||
); | ||
} | ||
expectPrototype.addAssertion = function (patternOrPatterns, handler, childExpect) { | ||
var _this6 = this; | ||
expectPrototype.addAssertion = function( | ||
patternOrPatterns, | ||
handler, | ||
childExpect | ||
) { | ||
var this$1 = this; | ||
if (this._frozen) { | ||
throw new Error('Cannot add an assertion to a frozen instance, please run .clone() first'); | ||
throw new Error( | ||
'Cannot add an assertion to a frozen instance, please run .clone() first' | ||
); | ||
} | ||
var maxArguments = void 0; | ||
var maxArguments; | ||
if (typeof childExpect === 'function') { | ||
@@ -646,10 +711,22 @@ maxArguments = 3; | ||
} | ||
if (arguments.length > maxArguments || typeof handler !== 'function' || typeof patternOrPatterns !== 'string' && !Array.isArray(patternOrPatterns)) { | ||
var errorMessage = 'Syntax: expect.addAssertion(<string|array[string]>, function (expect, subject, ...) { ... });'; | ||
if ((typeof handler === 'string' || Array.isArray(handler)) && typeof arguments[2] === 'function') { | ||
errorMessage += '\nAs of Unexpected 10, the syntax for adding assertions that apply only to specific\n' + 'types has changed. See http://unexpected.js.org/api/addAssertion/'; | ||
if ( | ||
arguments.length > maxArguments || | ||
typeof handler !== 'function' || | ||
(typeof patternOrPatterns !== 'string' && !Array.isArray(patternOrPatterns)) | ||
) { | ||
var errorMessage = | ||
'Syntax: expect.addAssertion(<string|array[string]>, function (expect, subject, ...) { ... });'; | ||
if ( | ||
(typeof handler === 'string' || Array.isArray(handler)) && | ||
typeof arguments[2] === 'function' | ||
) { | ||
errorMessage += | ||
'\nAs of Unexpected 10, the syntax for adding assertions that apply only to specific\n' + | ||
'types has changed. See http://unexpected.js.org/api/addAssertion/'; | ||
} | ||
throw new Error(errorMessage); | ||
} | ||
var patterns = Array.isArray(patternOrPatterns) ? patternOrPatterns : [patternOrPatterns]; | ||
var patterns = Array.isArray(patternOrPatterns) | ||
? patternOrPatterns | ||
: [patternOrPatterns]; | ||
patterns.forEach(function (pattern) { | ||
@@ -660,3 +737,7 @@ if (typeof pattern !== 'string' || pattern === '') { | ||
if (pattern !== pattern.trim()) { | ||
throw new Error('Assertion patterns can\'t start or end with whitespace:\n\n ' + JSON.stringify(pattern)); | ||
throw new Error( | ||
("Assertion patterns can't start or end with whitespace:\n\n " + (JSON.stringify( | ||
pattern | ||
))) | ||
); | ||
} | ||
@@ -672,14 +753,14 @@ } | ||
patterns.forEach(function (pattern) { | ||
var assertionDeclarations = _this6.parseAssertion(pattern); | ||
assertionDeclarations.forEach(function (_ref13) { | ||
var assertion = _ref13.assertion, | ||
args = _ref13.args, | ||
subject = _ref13.subject; | ||
var assertionDeclarations = this$1.parseAssertion(pattern); | ||
assertionDeclarations.forEach(function (ref) { | ||
var assertion = ref.assertion; | ||
var args = ref.args; | ||
var subject = ref.subject; | ||
ensureValidUseOfParenthesesOrBrackets(assertion); | ||
var expandedAssertions = expandAssertion(assertion); | ||
expandedAssertions.forEach(function (_ref14) { | ||
var flags = _ref14.flags, | ||
alternations = _ref14.alternations, | ||
text = _ref14.text; | ||
expandedAssertions.forEach(function (ref) { | ||
var flags = ref.flags; | ||
var alternations = ref.alternations; | ||
var text = ref.text; | ||
@@ -689,6 +770,13 @@ Object.keys(flags).forEach(function (flag) { | ||
}); | ||
maxNumberOfArgs = Math.max(maxNumberOfArgs, args.reduce(function (previous, _ref15) { | ||
var maximum = _ref15.maximum; | ||
return previous + (maximum === null ? Infinity : maximum); | ||
}, 0)); | ||
maxNumberOfArgs = Math.max( | ||
maxNumberOfArgs, | ||
args.reduce( | ||
function (previous, ref) { | ||
var maximum = ref.maximum; | ||
return previous + (maximum === null ? Infinity : maximum); | ||
}, | ||
0 | ||
) | ||
); | ||
assertionHandlers.push({ | ||
@@ -708,3 +796,8 @@ handler: handler, | ||
if (handler.length - 2 > maxNumberOfArgs) { | ||
throw new Error('The provided assertion handler takes ' + (handler.length - 2) + ' parameters, but the type signature specifies a maximum of ' + maxNumberOfArgs + ':\n\n ' + JSON.stringify(patterns)); | ||
throw new Error( | ||
("The provided assertion handler takes " + (handler.length - | ||
2) + " parameters, but the type signature specifies a maximum of " + maxNumberOfArgs + ":\n\n " + (JSON.stringify( | ||
patterns | ||
))) | ||
); | ||
} | ||
@@ -722,3 +815,9 @@ | ||
var i = 0; | ||
while (i < assertionHandlers.length && compareSpecificities(handler.specificity, assertionHandlers[i].specificity) > 0) { | ||
while ( | ||
i < assertionHandlers.length && | ||
compareSpecificities( | ||
handler.specificity, | ||
assertionHandlers[i].specificity | ||
) > 0 | ||
) { | ||
i += 1; | ||
@@ -733,20 +832,29 @@ } | ||
expectPrototype.addType = function (type, childExpect) { | ||
var _this7 = this; | ||
expectPrototype.addType = function(type, childExpect) { | ||
var this$1 = this; | ||
if (this._frozen) { | ||
throw new Error('Cannot add a type to a frozen instance, please run .clone() first'); | ||
throw new Error( | ||
'Cannot add a type to a frozen instance, please run .clone() first' | ||
); | ||
} | ||
var baseType = void 0; | ||
if (typeof type.name !== 'string' || !/^[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])$/i.test(type.name)) { | ||
throw new Error('A type must be given a non-empty name and must match ^[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])$'); | ||
var baseType; | ||
if ( | ||
typeof type.name !== 'string' || | ||
!/^[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])$/i.test(type.name) | ||
) { | ||
throw new Error( | ||
'A type must be given a non-empty name and must match ^[a-z_](?:|[a-z0-9_.-]*[_a-z0-9])$' | ||
); | ||
} | ||
if (typeof type.identify !== 'function' && type.identify !== false) { | ||
throw new Error('Type ' + type.name + ' must specify an identify function or be declared abstract by setting identify to false'); | ||
throw new Error( | ||
("Type " + (type.name) + " must specify an identify function or be declared abstract by setting identify to false") | ||
); | ||
} | ||
if (this.typeByName[type.name]) { | ||
throw new Error('The type with the name ' + type.name + ' already exists'); | ||
throw new Error(("The type with the name " + (type.name) + " already exists")); | ||
} | ||
@@ -758,3 +866,3 @@ | ||
if (!baseType) { | ||
throw new Error('Unknown base type: ' + type.base); | ||
throw new Error(("Unknown base type: " + (type.base))); | ||
} | ||
@@ -768,8 +876,9 @@ } else { | ||
if (!output || !output.isMagicPen) { | ||
throw new Error('You need to pass the output to baseType.inspect() as the third parameter'); | ||
throw new Error( | ||
'You need to pass the output to baseType.inspect() as the third parameter' | ||
); | ||
} | ||
return baseType.inspect(value, depth, output, function (value, depth) { | ||
return output.clone().appendInspected(value, depth); | ||
}); | ||
return baseType.inspect(value, depth, output, function (value, depth) { return output.clone().appendInspected(value, depth); } | ||
); | ||
}; | ||
@@ -783,15 +892,18 @@ | ||
if (!output || !output.isMagicPen) { | ||
throw new Error('You need to pass the output to baseType.diff() as the third parameter'); | ||
throw new Error( | ||
'You need to pass the output to baseType.diff() as the third parameter' | ||
); | ||
} | ||
return baseType.diff(actual, expected, output.clone(), function (actual, expected) { | ||
return _this7.diff(actual, expected, output.clone()); | ||
}, function (value, depth) { | ||
return output.clone().appendInspected(value, depth); | ||
}, _this7.equal.bind(_this7)); | ||
return baseType.diff( | ||
actual, | ||
expected, | ||
output.clone(), | ||
function (actual, expected) { return this$1.diff(actual, expected, output.clone()); }, | ||
function (value, depth) { return output.clone().appendInspected(value, depth); }, | ||
this$1.equal.bind(this$1) | ||
); | ||
}; | ||
extendedBaseType.equal = function (actual, expected) { | ||
return baseType.equal(actual, expected, _this7.equal.bind(_this7)); | ||
}; | ||
extendedBaseType.equal = function (actual, expected) { return baseType.equal(actual, expected, this$1.equal.bind(this$1)); }; | ||
@@ -805,13 +917,16 @@ var extendedType = extend({}, baseType, type, { | ||
if (nodeJsCustomInspect !== 'inspect') { | ||
extendedType[nodeJsCustomInspect] = function () { | ||
return 'type: ' + type.name; | ||
extendedType[nodeJsCustomInspect] = function() { | ||
return ("type: " + (type.name)); | ||
}; | ||
} | ||
extendedType.inspect = function (obj, depth, output, inspect) { | ||
if (arguments.length < 2 || !output || !output.isMagicPen) { | ||
return 'type: ' + type.name; | ||
extendedType.inspect = function(obj, depth, output, inspect) { | ||
if (arguments.length < 2 || (!output || !output.isMagicPen)) { | ||
return ("type: " + (type.name)); | ||
} else if (childExpect) { | ||
var childOutput = childExpect.createOutput(output.format); | ||
return originalInspect.call(this, obj, depth, childOutput, inspect) || childOutput; | ||
return ( | ||
originalInspect.call(this, obj, depth, childOutput, inspect) || | ||
childOutput | ||
); | ||
} else { | ||
@@ -825,7 +940,24 @@ return originalInspect.call(this, obj, depth, output, inspect) || output; | ||
var originalDiff = extendedType.diff; | ||
extendedType.diff = function (actual, expected, output, inspect, diff, equal) { | ||
extendedType.diff = function( | ||
actual, | ||
expected, | ||
output, | ||
inspect, | ||
diff, | ||
equal | ||
) { | ||
var childOutput = childExpect.createOutput(output.format); | ||
// Make sure that already buffered up output is preserved: | ||
childOutput.output = output.output; | ||
return originalDiff.call(this, actual, expected, childOutput, inspect, diff, equal) || output; | ||
return ( | ||
originalDiff.call( | ||
this, | ||
actual, | ||
expected, | ||
childOutput, | ||
inspect, | ||
diff, | ||
equal | ||
) || output | ||
); | ||
}; | ||
@@ -847,19 +979,32 @@ } | ||
expectPrototype.getType = function (typeName) { | ||
return this.typeByName[typeName] || this.parent && this.parent.getType(typeName); | ||
expectPrototype.getType = function(typeName) { | ||
return ( | ||
this.typeByName[typeName] || (this.parent && this.parent.getType(typeName)) | ||
); | ||
}; | ||
expectPrototype.findTypeOf = function (obj) { | ||
return utils.findFirst(this.types || [], function (type) { | ||
return type.identify && type.identify(obj); | ||
}) || this.parent && this.parent.findTypeOf(obj); | ||
expectPrototype.findTypeOf = function(obj) { | ||
return ( | ||
utils.findFirst( | ||
this.types || [], | ||
function (type) { return type.identify && type.identify(obj); } | ||
) || | ||
(this.parent && this.parent.findTypeOf(obj)) | ||
); | ||
}; | ||
expectPrototype.findTypeOfWithParentType = function (obj, requiredParentType) { | ||
return utils.findFirst(this.types || [], function (type) { | ||
return type.identify && type.identify(obj) && (!requiredParentType || type.is(requiredParentType)); | ||
}) || this.parent && this.parent.findTypeOfWithParentType(obj, requiredParentType); | ||
expectPrototype.findTypeOfWithParentType = function(obj, requiredParentType) { | ||
return ( | ||
utils.findFirst( | ||
this.types || [], | ||
function (type) { return type.identify && | ||
type.identify(obj) && | ||
(!requiredParentType || type.is(requiredParentType)); } | ||
) || | ||
(this.parent && | ||
this.parent.findTypeOfWithParentType(obj, requiredParentType)) | ||
); | ||
}; | ||
expectPrototype.findCommonType = function (a, b) { | ||
expectPrototype.findCommonType = function(a, b) { | ||
var aAncestorIndex = {}; | ||
@@ -880,19 +1025,27 @@ var current = this.findTypeOf(a); | ||
expectPrototype.addStyle = function () { | ||
var _output; | ||
expectPrototype.addStyle = function() { | ||
var ref; | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
if (this._frozen) { | ||
throw new Error('Cannot add a style to a frozen instance, please run .clone() first'); | ||
throw new Error( | ||
'Cannot add a style to a frozen instance, please run .clone() first' | ||
); | ||
} | ||
(_output = this.output).addStyle.apply(_output, arguments); | ||
(ref = this.output).addStyle.apply(ref, args); | ||
return this; | ||
}; | ||
expectPrototype.installTheme = function () { | ||
var _output2; | ||
expectPrototype.installTheme = function() { | ||
var ref; | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
if (this._frozen) { | ||
throw new Error('Cannot install a theme into a frozen instance, please run .clone() first'); | ||
throw new Error( | ||
'Cannot install a theme into a frozen instance, please run .clone() first' | ||
); | ||
} | ||
(_output2 = this.output).installTheme.apply(_output2, arguments); | ||
(ref = this.output).installTheme.apply(ref, args); | ||
return this; | ||
@@ -909,9 +1062,23 @@ }; | ||
expectPrototype.use = function (plugin) { | ||
expectPrototype.use = function(plugin) { | ||
this._assertTopLevelExpect(); | ||
if (this._frozen) { | ||
throw new Error('Cannot install a plugin into a frozen instance, please run .clone() first'); | ||
throw new Error( | ||
'Cannot install a plugin into a frozen instance, please run .clone() first' | ||
); | ||
} | ||
if (typeof plugin !== 'function' && ((typeof plugin === 'undefined' ? 'undefined' : (0, _typeof3.default)(plugin)) !== 'object' || typeof plugin.installInto !== 'function') || typeof plugin.name !== 'undefined' && typeof plugin.name !== 'string') { | ||
throw new Error('Plugins must be functions or adhere to the following interface\n' + '{\n' + ' name: <an optional plugin name>,\n' + ' version: <an optional semver version string>,\n' + ' installInto: <a function that will update the given expect instance>\n' + '}'); | ||
if ( | ||
(typeof plugin !== 'function' && | ||
(typeof plugin !== 'object' || | ||
typeof plugin.installInto !== 'function')) || | ||
(typeof plugin.name !== 'undefined' && typeof plugin.name !== 'string') | ||
) { | ||
throw new Error( | ||
'Plugins must be functions or adhere to the following interface\n' + | ||
'{\n' + | ||
' name: <an optional plugin name>,\n' + | ||
' version: <an optional semver version string>,\n' + | ||
' installInto: <a function that will update the given expect instance>\n' + | ||
'}' | ||
); | ||
} | ||
@@ -921,16 +1088,29 @@ | ||
var existingPlugin = utils.findFirst(this.installedPlugins, function (installedPlugin) { | ||
if (installedPlugin === plugin) { | ||
return true; | ||
} else { | ||
return pluginName && pluginName === getPluginName(installedPlugin); | ||
var existingPlugin = utils.findFirst( | ||
this.installedPlugins, | ||
function (installedPlugin) { | ||
if (installedPlugin === plugin) { | ||
return true; | ||
} else { | ||
return pluginName && pluginName === getPluginName(installedPlugin); | ||
} | ||
} | ||
}); | ||
); | ||
if (existingPlugin) { | ||
if (existingPlugin === plugin || typeof plugin.version !== 'undefined' && plugin.version === existingPlugin.version) { | ||
if ( | ||
existingPlugin === plugin || | ||
(typeof plugin.version !== 'undefined' && | ||
plugin.version === existingPlugin.version) | ||
) { | ||
// No-op | ||
return this; | ||
} else { | ||
throw new Error('Another instance of the plugin \'' + pluginName + '\' is already installed' + (typeof existingPlugin.version !== 'undefined' ? ' (version ' + existingPlugin.version + (typeof plugin.version !== 'undefined' ? ', trying to install ' + plugin.version : '') + ')' : '') + '. Please check your node_modules folder for unmet peerDependencies.'); | ||
throw new Error( | ||
("Another instance of the plugin '" + pluginName + "' is already installed" + (typeof existingPlugin.version !== 'undefined' | ||
? (" (version " + (existingPlugin.version) + (typeof plugin.version !== 'undefined' | ||
? (", trying to install " + (plugin.version)) | ||
: '') + ")") | ||
: '') + ". Please check your node_modules folder for unmet peerDependencies.") | ||
); | ||
} | ||
@@ -940,3 +1120,5 @@ } | ||
if (pluginName === 'unexpected-promise') { | ||
throw new Error('The unexpected-promise plugin was pulled into Unexpected as of 8.5.0. This means that the plugin is no longer supported.'); | ||
throw new Error( | ||
'The unexpected-promise plugin was pulled into Unexpected as of 8.5.0. This means that the plugin is no longer supported.' | ||
); | ||
} | ||
@@ -954,8 +1136,8 @@ | ||
expectPrototype.withError = function (body, handler) { | ||
return oathbreaker(makePromise(body).caught(function (e) { | ||
throwIfNonUnexpectedError(e); | ||
return handler(e); | ||
})); | ||
}; | ||
expectPrototype.withError = function (body, handler) { return oathbreaker( | ||
makePromise(body).caught(function (e) { | ||
throwIfNonUnexpectedError(e); | ||
return handler(e); | ||
}) | ||
); }; | ||
@@ -965,14 +1147,21 @@ expectPrototype.installPlugin = expectPrototype.use; // Legacy alias | ||
function calculateLimits(items) { | ||
return items.reduce(function (result, _ref16) { | ||
var minimum = _ref16.minimum, | ||
maximum = _ref16.maximum; | ||
return items.reduce( | ||
function (result, ref) { | ||
var minimum = ref.minimum; | ||
var maximum = ref.maximum; | ||
result.minimum += minimum; | ||
result.maximum += maximum; | ||
return result; | ||
}, { minimum: 0, maximum: 0 }); | ||
result.minimum += minimum; | ||
result.maximum += maximum; | ||
return result; | ||
}, | ||
{ minimum: 0, maximum: 0 } | ||
); | ||
} | ||
expectPrototype.throwAssertionNotFoundError = function (subject, testDescriptionString, args) { | ||
var _this8 = this; | ||
expectPrototype.throwAssertionNotFoundError = function( | ||
subject, | ||
testDescriptionString, | ||
args | ||
) { | ||
var this$1 = this; | ||
@@ -989,25 +1178,60 @@ var candidateHandlers = this.assertions[testDescriptionString]; | ||
this.fail({ | ||
message: function message(output) { | ||
var subjectOutput = function subjectOutput(output) { | ||
message: function (output) { | ||
var subjectOutput = function (output) { | ||
output.appendInspected(subject); | ||
}; | ||
var argsOutput = function argsOutput(output) { | ||
var argsOutput = function (output) { | ||
output.appendItems(args, ', '); | ||
}; | ||
output.append(createStandardErrorMessage(output.clone(), subjectOutput, testDescriptionString, argsOutput)).nl().indentLines(); | ||
output.i().error('The assertion does not have a matching signature for:').nl().indentLines().i().text('<').text(_this8.findTypeOf(subject).name).text('>').sp().text(testDescriptionString); | ||
output | ||
.append( | ||
createStandardErrorMessage( | ||
output.clone(), | ||
subjectOutput, | ||
testDescriptionString, | ||
argsOutput | ||
) | ||
) | ||
.nl() | ||
.indentLines(); | ||
output | ||
.i() | ||
.error('The assertion does not have a matching signature for:') | ||
.nl() | ||
.indentLines() | ||
.i() | ||
.text('<') | ||
.text(this$1.findTypeOf(subject).name) | ||
.text('>') | ||
.sp() | ||
.text(testDescriptionString); | ||
args.forEach(function (arg, i) { | ||
output.sp().text('<').text(_this8.findTypeOf(arg).name).text('>'); | ||
output | ||
.sp() | ||
.text('<') | ||
.text(this$1.findTypeOf(arg).name) | ||
.text('>'); | ||
}); | ||
output.outdentLines().nl().i().text('did you mean:').indentLines().nl(); | ||
var assertionDeclarations = Object.keys(candidateHandlers.reduce(function (result, _ref17) { | ||
var declaration = _ref17.declaration; | ||
output | ||
.outdentLines() | ||
.nl() | ||
.i() | ||
.text('did you mean:') | ||
.indentLines() | ||
.nl(); | ||
var assertionDeclarations = Object.keys( | ||
candidateHandlers.reduce(function (result, ref) { | ||
var declaration = ref.declaration; | ||
result[declaration] = true; | ||
return result; | ||
}, {})).sort(); | ||
result[declaration] = true; | ||
return result; | ||
}, {}) | ||
).sort(); | ||
assertionDeclarations.forEach(function (declaration, i) { | ||
output.nl(i > 0 ? 1 : 0).i().text(declaration); | ||
output | ||
.nl(i > 0 ? 1 : 0) | ||
.i() | ||
.text(declaration); | ||
}); | ||
@@ -1023,9 +1247,9 @@ output.outdentLines(); | ||
while (instance) { | ||
assertionStrings.push.apply(assertionStrings, (0, _toConsumableArray3.default)(Object.keys(instance.assertions))); | ||
assertionStrings.push.apply(assertionStrings, Object.keys(instance.assertions)); | ||
instance = instance.parent; | ||
} | ||
var compareAssertions = function compareAssertions(a, b) { | ||
var aAssertion = _this8.lookupAssertionRule(subject, a, args); | ||
var bAssertion = _this8.lookupAssertionRule(subject, b, args); | ||
var compareAssertions = function (a, b) { | ||
var aAssertion = this$1.lookupAssertionRule(subject, a, args); | ||
var bAssertion = this$1.lookupAssertionRule(subject, b, args); | ||
if (!aAssertion && !bAssertion) { | ||
@@ -1053,29 +1277,39 @@ return 0; | ||
var bestMatch = assertionsWithScore.sort(function (a, b) { | ||
var c = a.score - b.score; | ||
if (c !== 0) { | ||
return c; | ||
} | ||
var bestMatch = assertionsWithScore | ||
.sort(function (a, b) { | ||
var c = a.score - b.score; | ||
if (c !== 0) { | ||
return c; | ||
} | ||
if (a.assertion < b.assertion) { | ||
return -1; | ||
} else { | ||
return 1; | ||
} | ||
}).slice(0, 10).filter(function (_ref18, i, arr) { | ||
var score = _ref18.score; | ||
return Math.abs(score - arr[0].score) <= 2; | ||
}).sort(function (a, b) { | ||
var c = compareAssertions(a.assertion, b.assertion); | ||
if (c !== 0) { | ||
return c; | ||
} | ||
if (a.assertion < b.assertion) { | ||
return -1; | ||
} else { | ||
return 1; | ||
} | ||
}) | ||
.slice(0, 10) | ||
.filter(function (ref, i, arr) { | ||
var score = ref.score; | ||
return a.score - b.score; | ||
})[0]; | ||
return Math.abs(score - arr[0].score) <= 2; | ||
}) | ||
.sort(function (a, b) { | ||
var c = compareAssertions(a.assertion, b.assertion); | ||
if (c !== 0) { | ||
return c; | ||
} | ||
return a.score - b.score; | ||
})[0]; | ||
this.fail({ | ||
errorMode: 'bubbleThrough', | ||
message: function message(output) { | ||
output.error("Unknown assertion '").jsString(testDescriptionString).error("', did you mean: '").jsString(bestMatch.assertion).error("'"); | ||
output | ||
.error("Unknown assertion '") | ||
.jsString(testDescriptionString) | ||
.error("', did you mean: '") | ||
.jsString(bestMatch.assertion) | ||
.error("'"); | ||
} | ||
@@ -1085,9 +1319,16 @@ }); | ||
expectPrototype.lookupAssertionRule = function (subject, testDescriptionString, args, requireAssertionSuffix) { | ||
var _this9 = this; | ||
expectPrototype.lookupAssertionRule = function( | ||
subject, | ||
testDescriptionString, | ||
args, | ||
requireAssertionSuffix | ||
) { | ||
var this$1 = this; | ||
if (typeof testDescriptionString !== 'string') { | ||
throw new Error('The expect function requires the second parameter to be a string or an expect.it.'); | ||
throw new Error( | ||
'The expect function requires the second parameter to be a string or an expect.it.' | ||
); | ||
} | ||
var handlers = void 0; | ||
var handlers; | ||
var instance = this; | ||
@@ -1097,3 +1338,5 @@ while (instance) { | ||
if (instanceHandlers) { | ||
handlers = handlers ? handlers.concat(instanceHandlers) : instanceHandlers; | ||
handlers = handlers | ||
? handlers.concat(instanceHandlers) | ||
: instanceHandlers; | ||
} | ||
@@ -1107,6 +1350,6 @@ instance = instance.parent; | ||
var findTypeOf = function findTypeOf(value, key) { | ||
var findTypeOf = function (value, key) { | ||
var type = cachedTypes[key]; | ||
if (!type) { | ||
type = _this9.findTypeOf(value); | ||
type = this$1.findTypeOf(value); | ||
cachedTypes[key] = type; | ||
@@ -1117,3 +1360,3 @@ } | ||
var matches = function matches(value, assertionType, key, relaxed) { | ||
var matches = function (value, assertionType, key, relaxed) { | ||
if (assertionType.is('assertion') && typeof value === 'string') { | ||
@@ -1125,5 +1368,5 @@ return true; | ||
if (assertionType.identify === false) { | ||
return _this9.types.some(function (type) { | ||
return type.identify && type.is(assertionType) && type.identify(value); | ||
}); | ||
return this$1.types.some( | ||
function (type) { return type.identify && type.is(assertionType) && type.identify(value); } | ||
); | ||
} | ||
@@ -1146,3 +1389,6 @@ return assertionType.identify(value); | ||
if (args.length < requireArgumentsLength.minimum || requireArgumentsLength.maximum < args.length) { | ||
if ( | ||
args.length < requireArgumentsLength.minimum || | ||
requireArgumentsLength.maximum < args.length | ||
) { | ||
return false; | ||
@@ -1163,4 +1409,3 @@ } else if (args.length === 0 && requireArgumentsLength.maximum === 0) { | ||
var j = void 0, | ||
handler = void 0; | ||
var j, handler; | ||
for (j = 0; j < handlers.length; j += 1) { | ||
@@ -1182,3 +1427,3 @@ handler = handlers[j]; | ||
expectPrototype._assertTopLevelExpect = function () { | ||
expectPrototype._assertTopLevelExpect = function() { | ||
if (this !== this._topLevelExpect) { | ||
@@ -1189,13 +1434,21 @@ throw new Error('This method only works on the top level expect function'); | ||
expectPrototype._assertWrappedExpect = function () { | ||
expectPrototype._assertWrappedExpect = function() { | ||
if (this === this._topLevelExpect) { | ||
throw new Error('This method only works on the expect function handed to an assertion'); | ||
throw new Error( | ||
'This method only works on the expect function handed to an assertion' | ||
); | ||
} | ||
}; | ||
expectPrototype.setErrorMessage = function (err) { | ||
expectPrototype.setErrorMessage = function(err) { | ||
err.serializeMessage(this.outputFormat()); | ||
}; | ||
expectPrototype._createWrappedExpect = function (assertionRule, subject, args, testDescriptionString, context) { | ||
expectPrototype._createWrappedExpect = function( | ||
assertionRule, | ||
subject, | ||
args, | ||
testDescriptionString, | ||
context | ||
) { | ||
var flags = extend({}, assertionRule.flags); | ||
@@ -1205,13 +1458,20 @@ var parentExpect = this; | ||
function wrappedExpect(subject, testDescriptionString) { | ||
var arguments$1 = arguments; | ||
if (arguments.length === 0) { | ||
throw new Error('The expect function requires at least one parameter.'); | ||
} else if (arguments.length === 1) { | ||
return addAdditionalPromiseMethods(makePromise.resolve(subject), wrappedExpect, subject); | ||
return addAdditionalPromiseMethods( | ||
makePromise.resolve(subject), | ||
wrappedExpect, | ||
subject | ||
); | ||
} else if (typeof testDescriptionString === 'function') { | ||
wrappedExpect.errorMode = 'nested'; | ||
return wrappedExpect.withError(function () { | ||
return testDescriptionString(subject); | ||
}, function (err) { | ||
wrappedExpect.fail(err); | ||
}); | ||
return wrappedExpect.withError( | ||
function () { return testDescriptionString(subject); }, | ||
function (err) { | ||
wrappedExpect.fail(err); | ||
} | ||
); | ||
} | ||
@@ -1222,7 +1482,11 @@ testDescriptionString = utils.forwardFlags(testDescriptionString, flags); | ||
for (var i = 2; i < arguments.length; i += 1) { | ||
args[i - 2] = arguments[i]; | ||
args[i - 2] = arguments$1[i]; | ||
} | ||
return wrappedExpect._callInNestedContext(function () { | ||
return parentExpect._executeExpect(context.child(), subject, testDescriptionString, args); | ||
}); | ||
return wrappedExpect._callInNestedContext(function () { return parentExpect._executeExpect( | ||
context.child(), | ||
subject, | ||
testDescriptionString, | ||
args | ||
); } | ||
); | ||
} | ||
@@ -1246,3 +1510,7 @@ | ||
var argRule = wrappedExpect.assertionRule.args[i]; | ||
if (typeof arg === 'string' && (argRule && argRule.type.is('assertion') || wrappedExpect._getAssertionIndices().indexOf(i) >= 0)) { | ||
if ( | ||
typeof arg === 'string' && | ||
((argRule && argRule.type.is('assertion')) || | ||
wrappedExpect._getAssertionIndices().indexOf(i) >= 0) | ||
) { | ||
return new AssertionString(arg); | ||
@@ -1259,7 +1527,14 @@ } | ||
expectPrototype._executeExpect = function (context, subject, testDescriptionString, args) { | ||
var _assertionRule2; | ||
expectPrototype._executeExpect = function( | ||
context, | ||
subject, | ||
testDescriptionString, | ||
args | ||
) { | ||
var assertionRule = this.lookupAssertionRule( | ||
subject, | ||
testDescriptionString, | ||
args | ||
); | ||
var assertionRule = this.lookupAssertionRule(subject, testDescriptionString, args); | ||
if (!assertionRule) { | ||
@@ -1271,4 +1546,11 @@ var tokens = testDescriptionString.split(' '); | ||
var remainingTokens = tokens.slice(n); | ||
var argsWithAssertionPrepended = [remainingTokens.join(' ')].concat(args); | ||
assertionRule = this.lookupAssertionRule(subject, prefix, argsWithAssertionPrepended, true); | ||
var argsWithAssertionPrepended = [remainingTokens.join(' ')].concat( | ||
args | ||
); | ||
assertionRule = this.lookupAssertionRule( | ||
subject, | ||
prefix, | ||
argsWithAssertionPrepended, | ||
true | ||
); | ||
if (assertionRule) { | ||
@@ -1279,3 +1561,7 @@ // Found the longest prefix of the string that yielded a suitable assertion for the given subject and args | ||
for (var i = 1; i < remainingTokens.length; i += 1) { | ||
if (this.assertions.hasOwnProperty(remainingTokens.slice(0, i + 1).join(' '))) { | ||
if ( | ||
this.assertions.hasOwnProperty( | ||
remainingTokens.slice(0, i + 1).join(' ') | ||
) | ||
) { | ||
testDescriptionString = prefix; | ||
@@ -1295,14 +1581,18 @@ args = argsWithAssertionPrepended; | ||
if (assertionRule.expect && assertionRule.expect !== this) { | ||
var _assertionRule; | ||
return (_assertionRule = assertionRule).expect.apply(_assertionRule, [subject, testDescriptionString].concat((0, _toConsumableArray3.default)(args))); | ||
return assertionRule.expect.apply(assertionRule, [ subject, testDescriptionString ].concat( args )); | ||
} | ||
var wrappedExpect = this._createWrappedExpect(assertionRule, subject, args, testDescriptionString, context); | ||
var wrappedExpect = this._createWrappedExpect( | ||
assertionRule, | ||
subject, | ||
args, | ||
testDescriptionString, | ||
context | ||
); | ||
return oathbreaker((_assertionRule2 = assertionRule).handler.apply(_assertionRule2, [wrappedExpect, subject].concat((0, _toConsumableArray3.default)(args)))); | ||
return oathbreaker(assertionRule.handler.apply(assertionRule, [ wrappedExpect, subject ].concat( args ))); | ||
}; | ||
expectPrototype._expect = function expect(context, args) { | ||
var _this10 = this; | ||
var this$1 = this; | ||
@@ -1315,11 +1605,17 @@ var subject = args[0]; | ||
} else if (typeof testDescriptionString === 'function') { | ||
return this.withError(function () { | ||
return testDescriptionString(subject); | ||
}, function (err) { | ||
_this10.fail(err); | ||
}); | ||
return this.withError( | ||
function () { return testDescriptionString(subject); }, | ||
function (err) { | ||
this$1.fail(err); | ||
} | ||
); | ||
} | ||
try { | ||
var result = this._executeExpect(context, subject, testDescriptionString, Array.prototype.slice.call(args, 2)); | ||
var result = this._executeExpect( | ||
context, | ||
subject, | ||
testDescriptionString, | ||
Array.prototype.slice.call(args, 2) | ||
); | ||
if (utils.isPromise(result)) { | ||
@@ -1331,3 +1627,3 @@ result = wrapPromiseIfNecessary(result); | ||
if (e && e._isUnexpected && context.level === 0) { | ||
_this10.setErrorMessage(e); | ||
this$1.setErrorMessage(e); | ||
} | ||
@@ -1356,10 +1652,12 @@ throw e; | ||
expectPrototype.diff = function (a, b) { | ||
var output = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.createOutput(); | ||
expectPrototype.diff = function( | ||
a, | ||
b, | ||
output, | ||
recursions, | ||
seen | ||
) { | ||
var this$1 = this; | ||
if ( output === void 0 ) output = this.createOutput(); | ||
var _this11 = this; | ||
var recursions = arguments[3]; | ||
var seen = arguments[4]; | ||
var maxRecursions = 100; | ||
@@ -1376,12 +1674,13 @@ recursions = typeof recursions === 'number' ? recursions : maxRecursions; | ||
return this.findCommonType(a, b).diff(a, b, output, function (actual, expected) { | ||
return _this11.diff(actual, expected, output.clone(), recursions - 1, seen); | ||
}, function (v, depth) { | ||
return output.clone().appendInspected(v, depth); | ||
}, function (actual, expected) { | ||
return _this11.equal(actual, expected); | ||
}); | ||
return this.findCommonType(a, b).diff( | ||
a, | ||
b, | ||
output, | ||
function (actual, expected) { return this$1.diff(actual, expected, output.clone(), recursions - 1, seen); }, | ||
function (v, depth) { return output.clone().appendInspected(v, depth); }, | ||
function (actual, expected) { return this$1.equal(actual, expected); } | ||
); | ||
}; | ||
expectPrototype.toString = function () { | ||
expectPrototype.toString = function() { | ||
var assertions = this.assertions; | ||
@@ -1392,12 +1691,14 @@ | ||
var pen = magicpen(); | ||
Object.keys(assertions).sort().forEach(function (key) { | ||
assertions[key].forEach(function (_ref19) { | ||
var declaration = _ref19.declaration; | ||
Object.keys(assertions) | ||
.sort() | ||
.forEach(function (key) { | ||
assertions[key].forEach(function (ref) { | ||
var declaration = ref.declaration; | ||
if (!seen[declaration]) { | ||
declarations.push(declaration); | ||
seen[declaration] = true; | ||
} | ||
if (!seen[declaration]) { | ||
declarations.push(declaration); | ||
seen[declaration] = true; | ||
} | ||
}); | ||
}); | ||
}); | ||
@@ -1410,6 +1711,6 @@ declarations.forEach(function (declaration) { | ||
expectPrototype.clone = function () { | ||
expectPrototype.clone = function() { | ||
this._assertTopLevelExpect(); | ||
var clonedAssertions = {}; | ||
Object.keys(this.assertions).forEach(function (assertion) { | ||
Object.keys(this.assertions).forEach(function(assertion) { | ||
clonedAssertions[assertion] = [].concat(this.assertions[assertion]); | ||
@@ -1432,3 +1733,3 @@ }, this); | ||
expectPrototype.child = function () { | ||
expectPrototype.child = function() { | ||
this._assertTopLevelExpect(); | ||
@@ -1443,9 +1744,9 @@ var childExpect = createTopLevelExpect({ | ||
}); | ||
var parent = childExpect.parent = this; | ||
var parent = (childExpect.parent = this); | ||
childExpect.exportAssertion = function (testDescription, handler) { | ||
childExpect.exportAssertion = function(testDescription, handler) { | ||
parent.addAssertion(testDescription, handler, childExpect); | ||
return this; | ||
}; | ||
childExpect.exportType = function (type) { | ||
childExpect.exportType = function(type) { | ||
if (childExpect.getType(type.name) !== type) { | ||
@@ -1458,11 +1759,9 @@ childExpect.addType(type); | ||
}; | ||
childExpect.exportStyle = function (name, handler) { | ||
parent.addStyle(name, function () { | ||
childExpect.exportStyle = function(name, handler) { | ||
parent.addStyle(name, function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var childOutput = childExpect.createOutput(this.format); | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
this.append(handler.call.apply(handler, [childOutput].concat(args)) || childOutput); | ||
this.append(handler.call.apply(handler, [ childOutput ].concat( args )) || childOutput); | ||
}); | ||
@@ -1474,3 +1773,3 @@ return this; | ||
expectPrototype.freeze = function () { | ||
expectPrototype.freeze = function() { | ||
this._assertTopLevelExpect(); | ||
@@ -1481,3 +1780,3 @@ this._frozen = true; | ||
expectPrototype.outputFormat = function (format) { | ||
expectPrototype.outputFormat = function(format) { | ||
this._assertTopLevelExpect(); | ||
@@ -1492,6 +1791,6 @@ if (typeof format === 'undefined') { | ||
expectPrototype.createOutput = function (format) { | ||
expectPrototype.createOutput = function(format) { | ||
var that = this; | ||
var output = this.output.clone(format || 'text'); | ||
output.addStyle('appendInspected', function (value, depth) { | ||
output.addStyle('appendInspected', function(value, depth) { | ||
this.append(that.inspect(value, depth, this.clone())); | ||
@@ -1502,3 +1801,3 @@ }); | ||
expectPrototype.hook = function (fn) { | ||
expectPrototype.hook = function(fn) { | ||
this._assertTopLevelExpect(); | ||
@@ -1509,12 +1808,11 @@ this._expect = fn(this._expect.bind(this)); | ||
// This is not super elegant, but wrappedExpect.fail was different: | ||
expectPrototype.fail = function () { | ||
var _this12 = this; | ||
expectPrototype.fail = function() { | ||
var this$1 = this; | ||
var ref; | ||
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
args[_key5] = arguments[_key5]; | ||
} | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
if (this === this._topLevelExpect) { | ||
try { | ||
this._fail.apply(this, args); | ||
(ref = this)._fail.apply(ref, args); | ||
} catch (e) { | ||
@@ -1528,5 +1826,5 @@ if (e && e._isUnexpected) { | ||
this._callInNestedContext(function () { | ||
var _context$expect; | ||
var ref; | ||
(_context$expect = _this12.context.expect).fail.apply(_context$expect, args); | ||
(ref = this$1.context.expect).fail.apply(ref, args); | ||
}); | ||
@@ -1540,3 +1838,3 @@ } | ||
if (instance.assertions[assertionString]) { | ||
assertions.push.apply(assertions, (0, _toConsumableArray3.default)(instance.assertions[assertionString])); | ||
assertions.push.apply(assertions, instance.assertions[assertionString]); | ||
} | ||
@@ -1551,3 +1849,6 @@ } | ||
} | ||
var straightforwardAssertions = lookupAssertionsInParentChain(assertionString, expect); | ||
var straightforwardAssertions = lookupAssertionsInParentChain( | ||
assertionString, | ||
expect | ||
); | ||
if (straightforwardAssertions.length > 0) { | ||
@@ -1560,3 +1861,6 @@ return straightforwardAssertions; | ||
var suffixAssertions = lookupAssertionsInParentChain(suffix, expect); | ||
if (findSuffixAssertions(tokens.slice(0, n).join(' '), expect) && suffixAssertions.length > 0) { | ||
if ( | ||
findSuffixAssertions(tokens.slice(0, n).join(' '), expect) && | ||
suffixAssertions.length > 0 | ||
) { | ||
return suffixAssertions; | ||
@@ -1568,7 +1872,7 @@ } | ||
expectPrototype.standardErrorMessage = function (output, options) { | ||
var _this13 = this; | ||
expectPrototype.standardErrorMessage = function(output, options) { | ||
var this$1 = this; | ||
this._assertWrappedExpect(); | ||
options = (typeof options === 'undefined' ? 'undefined' : (0, _typeof3.default)(options)) === 'object' ? options : {}; | ||
options = typeof options === 'object' ? options : {}; | ||
@@ -1581,10 +1885,16 @@ if ('omitSubject' in output) { | ||
options.compactSubject = function (output) { | ||
output.jsFunctionName(_this13.subjectType.name); | ||
output.jsFunctionName(this$1.subjectType.name); | ||
}; | ||
} | ||
return createStandardErrorMessage(output, this.subjectOutput, this.testDescription, this.argsOutput, options); | ||
return createStandardErrorMessage( | ||
output, | ||
this.subjectOutput, | ||
this.testDescription, | ||
this.argsOutput, | ||
options | ||
); | ||
}; | ||
expectPrototype._callInNestedContext = function (callback) { | ||
var _this14 = this; | ||
expectPrototype._callInNestedContext = function(callback) { | ||
var this$1 = this; | ||
@@ -1599,3 +1909,3 @@ this._assertWrappedExpect(); | ||
if (e && e._isUnexpected) { | ||
var wrappedError = new UnexpectedError(_this14, e); | ||
var wrappedError = new UnexpectedError(this$1, e); | ||
wrappedError.originalError = e.originalError; | ||
@@ -1621,4 +1931,5 @@ throw wrappedError; | ||
expectPrototype.shift = function (subject, assertionIndex) { | ||
var _this15 = this; | ||
expectPrototype.shift = function(subject, assertionIndex) { | ||
var this$1 = this; | ||
var ref; | ||
@@ -1645,3 +1956,3 @@ this._assertWrappedExpect(); | ||
if (assertionIndex !== -1) { | ||
var _args = this.args.slice(0, assertionIndex); | ||
var args = this.args.slice(0, assertionIndex); | ||
var rest = this.args.slice(assertionIndex); | ||
@@ -1652,3 +1963,3 @@ var nextArgumentType = this.findTypeOf(rest[0]); | ||
this.argsOutput = function (output) { | ||
_args.forEach(function (arg, index) { | ||
args.forEach(function (arg, index) { | ||
if (index > 0) { | ||
@@ -1660,3 +1971,3 @@ output.text(', '); | ||
if (_args.length > 0) { | ||
if (args.length > 0) { | ||
output.sp(); | ||
@@ -1681,9 +1992,10 @@ } | ||
if (nextArgumentType.is('expect.it')) { | ||
return this.withError(function () { | ||
return rest[0](subject); | ||
}, function (err) { | ||
_this15.fail(err); | ||
}); | ||
return this.withError( | ||
function () { return rest[0](subject); }, | ||
function (err) { | ||
this$1.fail(err); | ||
} | ||
); | ||
} else if (nextArgumentType.is('string')) { | ||
return this.execute.apply(this, [subject].concat((0, _toConsumableArray3.default)(rest))); | ||
return (ref = this).execute.apply(ref, [ subject ].concat( rest )); | ||
} else { | ||
@@ -1698,9 +2010,12 @@ return subject; | ||
expectPrototype._getSubjectType = function () { | ||
expectPrototype._getSubjectType = function() { | ||
this._assertWrappedExpect(); | ||
return this.findTypeOfWithParentType(this.subject, this.assertionRule.subject.type); | ||
return this.findTypeOfWithParentType( | ||
this.subject, | ||
this.assertionRule.subject.type | ||
); | ||
}; | ||
expectPrototype._getArgTypes = function (index) { | ||
var _this16 = this; | ||
expectPrototype._getArgTypes = function(index) { | ||
var this$1 = this; | ||
@@ -1710,11 +2025,14 @@ this._assertWrappedExpect(); | ||
return this.args.map(function (arg, index) { | ||
return _this16.findTypeOfWithParentType(arg, _this16.assertionRule.args[Math.min(index, lastIndex)].type); | ||
return this$1.findTypeOfWithParentType( | ||
arg, | ||
this$1.assertionRule.args[Math.min(index, lastIndex)].type | ||
); | ||
}); | ||
}; | ||
expectPrototype._getAssertionIndices = function () { | ||
expectPrototype._getAssertionIndices = function() { | ||
this._assertWrappedExpect(); | ||
if (!this._assertionIndices) { | ||
var assertionIndices = []; | ||
var _args2 = this.args; | ||
var args = this.args; | ||
var currentAssertionRule = this.assertionRule; | ||
@@ -1724,5 +2042,13 @@ var offset = 0; | ||
OUTER: while (true) { | ||
if (currentAssertionRule.args.length > 1 && isAssertionArg(currentAssertionRule.args[currentAssertionRule.args.length - 2])) { | ||
if ( | ||
currentAssertionRule.args.length > 1 && | ||
isAssertionArg( | ||
currentAssertionRule.args[currentAssertionRule.args.length - 2] | ||
) | ||
) { | ||
assertionIndices.push(offset + currentAssertionRule.args.length - 2); | ||
var suffixAssertions = findSuffixAssertions(_args2[offset + currentAssertionRule.args.length - 2], this); | ||
var suffixAssertions = findSuffixAssertions( | ||
args[offset + currentAssertionRule.args.length - 2], | ||
this | ||
); | ||
if (suffixAssertions) { | ||
@@ -1763,20 +2089,14 @@ for (var i = 0; i < suffixAssertions.length; i += 1) { | ||
function createTopLevelExpect() { | ||
var _ref20 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref20$assertions = _ref20.assertions, | ||
assertions = _ref20$assertions === undefined ? {} : _ref20$assertions, | ||
_ref20$typeByName = _ref20.typeByName, | ||
typeByName = _ref20$typeByName === undefined ? { any: anyType } : _ref20$typeByName, | ||
_ref20$types = _ref20.types, | ||
types = _ref20$types === undefined ? [anyType] : _ref20$types, | ||
output = _ref20.output, | ||
_ref20$format = _ref20.format, | ||
format = _ref20$format === undefined ? magicpen.defaultFormat : _ref20$format, | ||
_ref20$installedPlugi = _ref20.installedPlugins, | ||
installedPlugins = _ref20$installedPlugi === undefined ? [] : _ref20$installedPlugi; | ||
function createTopLevelExpect(ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var assertions = ref.assertions; if ( assertions === void 0 ) assertions = {}; | ||
var typeByName = ref.typeByName; if ( typeByName === void 0 ) typeByName = { any: anyType }; | ||
var types = ref.types; if ( types === void 0 ) types = [anyType]; | ||
var output = ref.output; | ||
var format = ref.format; if ( format === void 0 ) format = magicpen.defaultFormat; | ||
var installedPlugins = ref.installedPlugins; if ( installedPlugins === void 0 ) installedPlugins = []; | ||
var expect = function expect() { | ||
for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) { | ||
args[_key6] = arguments[_key6]; | ||
} | ||
var expect = function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
@@ -1803,2 +2123,2 @@ return expect._expect(new Context(expect), args); | ||
module.exports = createTopLevelExpect; | ||
module.exports = createTopLevelExpect; |
/* global window */ | ||
var defaultDepth = 3; | ||
var matchDepthParameter = typeof window !== 'undefined' && typeof window.location !== 'undefined' && window.location.search.match(/[?&]depth=(\d+)(?:$|&)/); | ||
var matchDepthParameter = | ||
typeof window !== 'undefined' && | ||
typeof window.location !== 'undefined' && | ||
window.location.search.match(/[?&]depth=(\d+)(?:$|&)/); | ||
@@ -10,2 +13,2 @@ if (matchDepthParameter) { | ||
} | ||
module.exports = defaultDepth; | ||
module.exports = defaultDepth; |
@@ -15,19 +15,29 @@ function ensureValidUseOfParenthesesOrBrackets(pattern) { | ||
if (counts['['] === counts[']'] + 1) { | ||
throw new Error('Assertion patterns must not contain flags with brackets: \'' + pattern + '\''); | ||
throw new Error( | ||
("Assertion patterns must not contain flags with brackets: '" + pattern + "'") | ||
); | ||
} | ||
if (counts['('] !== counts[')']) { | ||
throw new Error('Assertion patterns must not contain flags with parentheses: \'' + pattern + '\''); | ||
throw new Error( | ||
("Assertion patterns must not contain flags with parentheses: '" + pattern + "'") | ||
); | ||
} | ||
if (pattern.charAt(i - 1) === '[') { | ||
throw new Error('Assertion patterns must not contain empty flags: \'' + pattern + '\''); | ||
throw new Error( | ||
("Assertion patterns must not contain empty flags: '" + pattern + "'") | ||
); | ||
} | ||
} else if (c === ')' && counts['('] >= counts[')']) { | ||
if (counts['('] === counts[')'] + 1) { | ||
throw new Error('Assertion patterns must not contain alternations with parentheses: \'' + pattern + '\''); | ||
throw new Error( | ||
("Assertion patterns must not contain alternations with parentheses: '" + pattern + "'") | ||
); | ||
} | ||
if (counts['['] !== counts[']']) { | ||
throw new Error('Assertion patterns must not contain alternations with brackets: \'' + pattern + '\''); | ||
throw new Error( | ||
("Assertion patterns must not contain alternations with brackets: '" + pattern + "'") | ||
); | ||
} | ||
@@ -38,10 +48,14 @@ } | ||
if (counts['['] !== counts[']']) { | ||
throw new Error('Assertion patterns must not contain unbalanced brackets: \'' + pattern + '\''); | ||
throw new Error( | ||
("Assertion patterns must not contain unbalanced brackets: '" + pattern + "'") | ||
); | ||
} | ||
if (counts['('] !== counts[')']) { | ||
throw new Error('Assertion patterns must not contain unbalanced parentheses: \'' + pattern + '\''); | ||
throw new Error( | ||
("Assertion patterns must not contain unbalanced parentheses: '" + pattern + "'") | ||
); | ||
} | ||
} | ||
module.exports = ensureValidUseOfParenthesesOrBrackets; | ||
module.exports = ensureValidUseOfParenthesesOrBrackets; |
@@ -1,7 +0,1 @@ | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var extend = require('./utils').extend; | ||
@@ -16,5 +10,3 @@ | ||
function removeEmptyStrings(texts) { | ||
return texts.filter(function (text) { | ||
return text !== ''; | ||
}); | ||
return texts.filter(function (text) { return text !== ''; }); | ||
} | ||
@@ -30,46 +22,57 @@ function createPermutations(tokens, index) { | ||
var flag = token.slice(1, -1); | ||
return tail.map(function (pattern) { | ||
var flags = {}; | ||
flags[flag] = true; | ||
return { | ||
text: flag + ' ' + pattern.text, | ||
flags: extend(flags, pattern.flags), | ||
alternations: pattern.alternations | ||
}; | ||
}).concat(tail.map(function (pattern) { | ||
var flags = {}; | ||
flags[flag] = false; | ||
return { | ||
text: pattern.text, | ||
flags: extend(flags, pattern.flags), | ||
alternations: pattern.alternations | ||
}; | ||
})); | ||
return tail | ||
.map(function (pattern) { | ||
var flags = {}; | ||
flags[flag] = true; | ||
return { | ||
text: (flag + " " + (pattern.text)), | ||
flags: extend(flags, pattern.flags), | ||
alternations: pattern.alternations | ||
}; | ||
}) | ||
.concat( | ||
tail.map(function (pattern) { | ||
var flags = {}; | ||
flags[flag] = false; | ||
return { | ||
text: pattern.text, | ||
flags: extend(flags, pattern.flags), | ||
alternations: pattern.alternations | ||
}; | ||
}) | ||
); | ||
} else if (isAlternation(token)) { | ||
return token.substr(1, token.length - 2) // Remove parentheses | ||
.split(/\|/).reduce(function (result, alternation) { | ||
return result.concat(tail.map(function (_ref) { | ||
var text = _ref.text, | ||
flags = _ref.flags, | ||
alternations = _ref.alternations; | ||
return { | ||
// Make sure that an empty alternation doesn't produce two spaces: | ||
text: alternation ? alternation + text : text.replace(/^ /, ''), | ||
return token | ||
.substr(1, token.length - 2) // Remove parentheses | ||
.split(/\|/) | ||
.reduce( | ||
function (result, alternation) { return result.concat( | ||
tail.map(function (ref) { | ||
var text = ref.text; | ||
var flags = ref.flags; | ||
var alternations = ref.alternations; | ||
flags: flags, | ||
alternations: [alternation].concat((0, _toConsumableArray3.default)(alternations)) | ||
}; | ||
})); | ||
}, []); | ||
return ({ | ||
// Make sure that an empty alternation doesn't produce two spaces: | ||
text: alternation ? alternation + text : text.replace(/^ /, ''), | ||
flags: flags, | ||
alternations: [alternation ].concat( alternations) | ||
}); | ||
}) | ||
); }, | ||
[] | ||
); | ||
} else { | ||
return tail.map(function (_ref2) { | ||
var text = _ref2.text, | ||
flags = _ref2.flags, | ||
alternations = _ref2.alternations; | ||
return { | ||
text: token + text, | ||
flags: flags, | ||
alternations: alternations | ||
}; | ||
return tail.map(function (ref) { | ||
var text = ref.text; | ||
var flags = ref.flags; | ||
var alternations = ref.alternations; | ||
return ({ | ||
text: token + text, | ||
flags: flags, | ||
alternations: alternations | ||
}); | ||
}); | ||
} | ||
@@ -82,5 +85,5 @@ } | ||
var tokens = []; | ||
var m = void 0; | ||
var m; | ||
var lastIndex = 0; | ||
while (m = splitRegex.exec(pattern)) { | ||
while ((m = splitRegex.exec(pattern))) { | ||
tokens.push(pattern.slice(lastIndex, m.index)); | ||
@@ -103,2 +106,2 @@ tokens.push(pattern.slice(m.index, splitRegex.lastIndex)); | ||
module.exports = expandAssertion; | ||
module.exports = expandAssertion; |
@@ -1,8 +0,17 @@ | ||
var expect = require('./createTopLevelExpect')().use(require('./styles')).use(require('./types')).use(require('./assertions')).freeze(); | ||
var expect = require('./createTopLevelExpect')() | ||
.use(require('./styles')) | ||
.use(require('./types')) | ||
.use(require('./assertions')) | ||
.freeze(); | ||
// Add an inspect method to all the promises we return that will make the REPL, console.log, and util.inspect render it nicely in node.js: | ||
require('unexpected-bluebird').prototype[require('./nodeJsCustomInspect')] = function () { | ||
return expect.createOutput(require('magicpen').defaultFormat).appendInspected(this).toString(); | ||
require('unexpected-bluebird').prototype[ | ||
require('./nodeJsCustomInspect') | ||
] = function() { | ||
return expect | ||
.createOutput(require('magicpen').defaultFormat) | ||
.appendInspected(this) | ||
.toString(); | ||
}; | ||
module.exports = expect; | ||
module.exports = expect; |
@@ -1,11 +0,1 @@ | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Promise = require('unexpected-bluebird'); | ||
@@ -17,3 +7,6 @@ var oathbreaker = require('./oathbreaker'); | ||
if (typeof body !== 'function') { | ||
throw new TypeError('expect.promise(...) requires a function argument to be supplied.\n' + 'See http://unexpected.js.org/api/promise/ for more details.'); | ||
throw new TypeError( | ||
'expect.promise(...) requires a function argument to be supplied.\n' + | ||
'See http://unexpected.js.org/api/promise/ for more details.' | ||
); | ||
} | ||
@@ -27,3 +20,3 @@ | ||
var runningTasks = 0; | ||
var resolvedValue = void 0; | ||
var resolvedValue; | ||
var outerFunctionHasReturned = false; | ||
@@ -38,3 +31,6 @@ | ||
function noteResolvedValue(value) { | ||
if (typeof value !== 'undefined' && typeof resolvedValue === 'undefined') { | ||
if ( | ||
typeof value !== 'undefined' && | ||
typeof resolvedValue === 'undefined' | ||
) { | ||
resolvedValue = value; | ||
@@ -44,10 +40,13 @@ } | ||
var runner = function runner(fn) { | ||
var runner = function (fn) { | ||
runningTasks += 1; | ||
return function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
runningTasks -= 1; | ||
var result = void 0; | ||
var result; | ||
try { | ||
if (typeof fn === 'function') { | ||
result = oathbreaker(fn.apply(undefined, arguments)); | ||
result = oathbreaker(fn.apply(void 0, args)); | ||
if (isPromise(result)) { | ||
@@ -93,3 +92,3 @@ runningTasks += 1; | ||
function isPromise(obj) { | ||
return obj && (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) === 'object' && typeof obj.then === 'function'; | ||
return obj && typeof obj === 'object' && typeof obj.then === 'function'; | ||
} | ||
@@ -100,7 +99,7 @@ | ||
return [obj]; | ||
} else if (obj && (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) === 'object') { | ||
} else if (obj && typeof obj === 'object') { | ||
var promises = []; | ||
// Object or Array | ||
Object.keys(obj).forEach(function (key) { | ||
promises.push.apply(promises, (0, _toConsumableArray3.default)(extractPromisesFromObject(obj[key]))); | ||
promises.push.apply(promises, extractPromisesFromObject(obj[key])); | ||
}); | ||
@@ -132,3 +131,7 @@ return promises; | ||
Object.keys(Promise).forEach(function (staticMethodName) { | ||
if (!/^_|^on|^setScheduler|ongStackTraces/.test(staticMethodName) && typeof Promise[staticMethodName] === 'function' && typeof makePromise[staticMethodName] === 'undefined') { | ||
if ( | ||
!/^_|^on|^setScheduler|ongStackTraces/.test(staticMethodName) && | ||
typeof Promise[staticMethodName] === 'function' && | ||
typeof makePromise[staticMethodName] === 'undefined' | ||
) { | ||
makePromise[staticMethodName] = Promise[staticMethodName]; | ||
@@ -138,2 +141,2 @@ } | ||
module.exports = makePromise; | ||
module.exports = makePromise; |
@@ -8,2 +8,2 @@ module.exports = 'inspect'; | ||
} | ||
} catch (err) {} | ||
} catch (err) {} |
@@ -1,7 +0,1 @@ | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* global afterEach, jasmine */ | ||
@@ -13,3 +7,3 @@ var pendingPromisesForTheCurrentTest = []; | ||
if ((typeof jasmine === 'undefined' ? 'undefined' : (0, _typeof3.default)(jasmine)) === 'object') { | ||
if (typeof jasmine === 'object') { | ||
// Add a custom reporter that allows us to capture the name of the currently executing spec: | ||
@@ -27,3 +21,5 @@ jasmine.getEnv().addReporter({ | ||
function isPendingOrHasUnhandledRejection(promise) { | ||
return promise.isPending() || promise.isRejected() && promise.reason().uncaught; | ||
return ( | ||
promise.isPending() || (promise.isRejected() && promise.reason().uncaught) | ||
); | ||
} | ||
@@ -35,7 +31,11 @@ | ||
try { | ||
afterEach(function () { | ||
var error = void 0; | ||
afterEach(function() { | ||
var error; | ||
var testPassed = true; | ||
if (pendingPromisesForTheCurrentTest.some(isPendingOrHasUnhandledRejection)) { | ||
var displayName = void 0; | ||
if ( | ||
pendingPromisesForTheCurrentTest.some( | ||
isPendingOrHasUnhandledRejection | ||
) | ||
) { | ||
var displayName; | ||
if (this.currentTest) { | ||
@@ -45,7 +45,9 @@ // mocha | ||
displayName = this.currentTest.title; | ||
} else if ((typeof currentSpec === 'undefined' ? 'undefined' : (0, _typeof3.default)(currentSpec)) === 'object') { | ||
} else if (typeof currentSpec === 'object') { | ||
testPassed = currentSpec.failedExpectations.length === 0; | ||
displayName = currentSpec.fullName; | ||
} | ||
error = new Error(displayName + ': You have created a promise that was not returned from the it block'); | ||
error = new Error( | ||
(displayName + ": You have created a promise that was not returned from the it block") | ||
); | ||
} | ||
@@ -71,2 +73,2 @@ pendingPromisesForTheCurrentTest = []; | ||
registerAfterEachHook(); | ||
}; | ||
}; |
@@ -27,15 +27,18 @@ var workQueue = require('./workQueue'); | ||
var onResolve = function onResolve() {}; | ||
var onReject = function onReject() {}; | ||
var onResolve = function () {}; | ||
var onReject = function () {}; | ||
var evaluated = false; | ||
var error = void 0; | ||
value.then(function (obj) { | ||
evaluated = true; | ||
onResolve(value); | ||
}, function (err) { | ||
evaluated = true; | ||
error = err; | ||
onReject(err); | ||
}); | ||
var error; | ||
value.then( | ||
function (obj) { | ||
evaluated = true; | ||
onResolve(value); | ||
}, | ||
function (err) { | ||
evaluated = true; | ||
error = err; | ||
onReject(err); | ||
} | ||
); | ||
@@ -59,2 +62,2 @@ workQueue.drain(); | ||
}); | ||
}; | ||
}; |
// eslint-disable-next-line no-control-regex | ||
module.exports = /([\x00-\x09\x0B-\x1F\x7F-\x9F\xAD\u0378\u0379\u037F-\u0383\u038B\u038D\u03A2\u0528-\u0530\u0557\u0558\u0560\u0588\u058B-\u058E\u0590\u05C8-\u05CF\u05EB-\u05EF\u05F5-\u0605\u061C\u061D\u06DD\u070E\u070F\u074B\u074C\u07B2-\u07BF\u07FB-\u07FF\u082E\u082F\u083F\u085C\u085D\u085F-\u089F\u08A1\u08AD-\u08E3\u08FF\u0978\u0980\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09FC-\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF2-\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B55\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B78-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BFB-\u0C00\u0C04\u0C0D\u0C11\u0C29\u0C34\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5A-\u0C5F\u0C64\u0C65\u0C70-\u0C77\u0C80\u0C81\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0D01\u0D04\u0D0D\u0D11\u0D3B\u0D3C\u0D45\u0D49\u0D4F-\u0D56\u0D58-\u0D5F\u0D64\u0D65\u0D76-\u0D78\u0D80\u0D81\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DF1\u0DF5-\u0E00\u0E3B-\u0E3E\u0E5C-\u0E80\u0E83\u0E85\u0E86\u0E89\u0E8B\u0E8C\u0E8E-\u0E93\u0E98\u0EA0\u0EA4\u0EA6\u0EA8\u0EA9\u0EAC\u0EBA\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F48\u0F6D-\u0F70\u0F98\u0FBD\u0FCD\u0FDB-\u0FFF\u10C6\u10C8-\u10CC\u10CE\u10CF\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u137D-\u137F\u139A-\u139F\u13F5-\u13FF\u169D-\u169F\u16F1-\u16FF\u170D\u1715-\u171F\u1737-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17DE\u17DF\u17EA-\u17EF\u17FA-\u17FF\u180F\u181A-\u181F\u1878-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191D-\u191F\u192C-\u192F\u193C-\u193F\u1941-\u1943\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19DD\u1A1C\u1A1D\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1A9F\u1AAE-\u1AFF\u1B4C-\u1B4F\u1B7D-\u1B7F\u1BF4-\u1BFB\u1C38-\u1C3A\u1C4A-\u1C4C\u1C80-\u1CBF\u1CC8-\u1CCF\u1CF7-\u1CFF\u1DE7-\u1DFB\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FC5\u1FD4\u1FD5\u1FDC\u1FF0\u1FF1\u1FF5\u1FFF\u200B-\u200F\u202A-\u202E\u2060-\u206F\u2072\u2073\u208F\u209D-\u209F\u20BA-\u20CF\u20F1-\u20FF\u218A-\u218F\u23F4-\u23FF\u2427-\u243F\u244B-\u245F\u2700\u2B4D-\u2B4F\u2B5A-\u2BFF\u2C2F\u2C5F\u2CF4-\u2CF8\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D71-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E3C-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3040\u3097\u3098\u3100-\u3104\u312E-\u3130\u318F\u31BB-\u31BF\u31E4-\u31EF\u321F\u32FF\u4DB6-\u4DBF\u9FCD-\u9FFF\uA48D-\uA48F\uA4C7-\uA4CF\uA62C-\uA63F\uA698-\uA69E\uA6F8-\uA6FF\uA78F\uA794-\uA79F\uA7AB-\uA7F7\uA82C-\uA82F\uA83A-\uA83F\uA878-\uA87F\uA8C5-\uA8CD\uA8DA-\uA8DF\uA8FC-\uA8FF\uA954-\uA95E\uA97D-\uA97F\uA9CE\uA9DA-\uA9DD\uA9E0-\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A\uAA5B\uAA7C-\uAA7F\uAAC3-\uAADA\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F-\uABBF\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBC2-\uFBD2\uFD40-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFE\uFDFF\uFE1A-\uFE1F\uFE27-\uFE2F\uFE53\uFE67\uFE6C-\uFE6F\uFE75\uFEFD-\uFF00\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF])/g; | ||
module.exports = /([\x00-\x09\x0B-\x1F\x7F-\x9F\xAD\u0378\u0379\u037F-\u0383\u038B\u038D\u03A2\u0528-\u0530\u0557\u0558\u0560\u0588\u058B-\u058E\u0590\u05C8-\u05CF\u05EB-\u05EF\u05F5-\u0605\u061C\u061D\u06DD\u070E\u070F\u074B\u074C\u07B2-\u07BF\u07FB-\u07FF\u082E\u082F\u083F\u085C\u085D\u085F-\u089F\u08A1\u08AD-\u08E3\u08FF\u0978\u0980\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09FC-\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF2-\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B55\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B78-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BFB-\u0C00\u0C04\u0C0D\u0C11\u0C29\u0C34\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5A-\u0C5F\u0C64\u0C65\u0C70-\u0C77\u0C80\u0C81\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0D01\u0D04\u0D0D\u0D11\u0D3B\u0D3C\u0D45\u0D49\u0D4F-\u0D56\u0D58-\u0D5F\u0D64\u0D65\u0D76-\u0D78\u0D80\u0D81\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DF1\u0DF5-\u0E00\u0E3B-\u0E3E\u0E5C-\u0E80\u0E83\u0E85\u0E86\u0E89\u0E8B\u0E8C\u0E8E-\u0E93\u0E98\u0EA0\u0EA4\u0EA6\u0EA8\u0EA9\u0EAC\u0EBA\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F48\u0F6D-\u0F70\u0F98\u0FBD\u0FCD\u0FDB-\u0FFF\u10C6\u10C8-\u10CC\u10CE\u10CF\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u137D-\u137F\u139A-\u139F\u13F5-\u13FF\u169D-\u169F\u16F1-\u16FF\u170D\u1715-\u171F\u1737-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17DE\u17DF\u17EA-\u17EF\u17FA-\u17FF\u180F\u181A-\u181F\u1878-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191D-\u191F\u192C-\u192F\u193C-\u193F\u1941-\u1943\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19DD\u1A1C\u1A1D\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1A9F\u1AAE-\u1AFF\u1B4C-\u1B4F\u1B7D-\u1B7F\u1BF4-\u1BFB\u1C38-\u1C3A\u1C4A-\u1C4C\u1C80-\u1CBF\u1CC8-\u1CCF\u1CF7-\u1CFF\u1DE7-\u1DFB\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FC5\u1FD4\u1FD5\u1FDC\u1FF0\u1FF1\u1FF5\u1FFF\u200B-\u200F\u202A-\u202E\u2060-\u206F\u2072\u2073\u208F\u209D-\u209F\u20BA-\u20CF\u20F1-\u20FF\u218A-\u218F\u23F4-\u23FF\u2427-\u243F\u244B-\u245F\u2700\u2B4D-\u2B4F\u2B5A-\u2BFF\u2C2F\u2C5F\u2CF4-\u2CF8\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D71-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E3C-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3040\u3097\u3098\u3100-\u3104\u312E-\u3130\u318F\u31BB-\u31BF\u31E4-\u31EF\u321F\u32FF\u4DB6-\u4DBF\u9FCD-\u9FFF\uA48D-\uA48F\uA4C7-\uA4CF\uA62C-\uA63F\uA698-\uA69E\uA6F8-\uA6FF\uA78F\uA794-\uA79F\uA7AB-\uA7F7\uA82C-\uA82F\uA83A-\uA83F\uA878-\uA87F\uA8C5-\uA8CD\uA8DA-\uA8DF\uA8FC-\uA8FF\uA954-\uA95E\uA97D-\uA97F\uA9CE\uA9DA-\uA9DD\uA9E0-\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A\uAA5B\uAA7C-\uAA7F\uAAC3-\uAADA\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F-\uABBF\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBC2-\uFBD2\uFD40-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFE\uFDFF\uFE1A-\uFE1F\uFE27-\uFE2F\uFE53\uFE67\uFE6C-\uFE6F\uFE75\uFEFD-\uFF00\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF])/g; |
@@ -1,7 +0,1 @@ | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var utils = require('./utils'); | ||
@@ -29,3 +23,20 @@ var stringDiff = require('diff'); | ||
expect.installTheme('html', { | ||
palette: ['#993333', '#669933', '#314575', '#337777', '#710071', '#319916', '#BB1A53', '#999933', '#4311C2', '#996633', '#993399', '#333399', '#228842', '#C24747', '#336699', '#663399'], | ||
palette: [ | ||
'#993333', | ||
'#669933', | ||
'#314575', | ||
'#337777', | ||
'#710071', | ||
'#319916', | ||
'#BB1A53', | ||
'#999933', | ||
'#4311C2', | ||
'#996633', | ||
'#993399', | ||
'#333399', | ||
'#228842', | ||
'#C24747', | ||
'#336699', | ||
'#663399' | ||
], | ||
styles: { | ||
@@ -43,3 +54,20 @@ jsComment: '#969896', | ||
expect.installTheme('ansi', { | ||
palette: ['#FF1A53', '#E494FF', '#1A53FF', '#FF1AC6', '#1AFF53', '#D557FF', '#81FF57', '#C6FF1A', '#531AFF', '#AFFF94', '#C61AFF', '#53FF1A', '#FF531A', '#1AFFC6', '#FFC61A', '#1AC6FF'], | ||
palette: [ | ||
'#FF1A53', | ||
'#E494FF', | ||
'#1A53FF', | ||
'#FF1AC6', | ||
'#1AFF53', | ||
'#D557FF', | ||
'#81FF57', | ||
'#C6FF1A', | ||
'#531AFF', | ||
'#AFFF94', | ||
'#C61AFF', | ||
'#53FF1A', | ||
'#FF531A', | ||
'#1AFFC6', | ||
'#FFC61A', | ||
'#1AC6FF' | ||
], | ||
styles: { | ||
@@ -60,3 +88,3 @@ jsComment: 'gray', | ||
expect.addStyle('colorByIndex', function (content, index) { | ||
expect.addStyle('colorByIndex', function(content, index) { | ||
var palette = this.theme().palette; | ||
@@ -71,34 +99,44 @@ if (palette) { | ||
expect.addStyle('singleQuotedString', function (content) { | ||
expect.addStyle('singleQuotedString', function(content) { | ||
content = String(content); | ||
this.jsString("'").jsString( | ||
// eslint-disable-next-line no-control-regex | ||
content.replace(/[\\\x00-\x1f']/g, function ($0) { | ||
if ($0 === '\n') { | ||
return '\\n'; | ||
} else if ($0 === '\r') { | ||
return '\\r'; | ||
} else if ($0 === "'") { | ||
return "\\'"; | ||
} else if ($0 === '\\') { | ||
return '\\\\'; | ||
} else if ($0 === '\t') { | ||
return '\\t'; | ||
} else if ($0 === '\b') { | ||
return '\\b'; | ||
} else if ($0 === '\f') { | ||
return '\\f'; | ||
} else { | ||
var charCode = $0.charCodeAt(0); | ||
return '\\x' + (charCode < 16 ? '0' : '') + charCode.toString(16); | ||
} | ||
})).jsString("'"); | ||
this.jsString("'") | ||
.jsString( | ||
// eslint-disable-next-line no-control-regex | ||
content.replace(/[\\\x00-\x1f']/g, function ($0) { | ||
if ($0 === '\n') { | ||
return '\\n'; | ||
} else if ($0 === '\r') { | ||
return '\\r'; | ||
} else if ($0 === "'") { | ||
return "\\'"; | ||
} else if ($0 === '\\') { | ||
return '\\\\'; | ||
} else if ($0 === '\t') { | ||
return '\\t'; | ||
} else if ($0 === '\b') { | ||
return '\\b'; | ||
} else if ($0 === '\f') { | ||
return '\\f'; | ||
} else { | ||
var charCode = $0.charCodeAt(0); | ||
return ("\\x" + (charCode < 16 ? '0' : '') + (charCode.toString(16))); | ||
} | ||
}) | ||
) | ||
.jsString("'"); | ||
}); | ||
expect.addStyle('propertyForObject', function (key, inspectedValue, isArrayLike) { | ||
expect.addStyle('propertyForObject', function( | ||
key, | ||
inspectedValue, | ||
isArrayLike | ||
) { | ||
var keyOmitted = false; | ||
var isSymbol = void 0; | ||
isSymbol = (typeof key === 'undefined' ? 'undefined' : (0, _typeof3.default)(key)) === 'symbol'; | ||
var isSymbol; | ||
isSymbol = typeof key === 'symbol'; | ||
if (isSymbol) { | ||
this.text('[').appendInspected(key).text(']').text(':'); | ||
this.text('[') | ||
.appendInspected(key) | ||
.text(']') | ||
.text(':'); | ||
} else { | ||
@@ -121,3 +159,7 @@ key = String(key); | ||
if (!keyOmitted) { | ||
if (key.length > 5 && inspectedValue.isBlock() && inspectedValue.isMultiline()) { | ||
if ( | ||
key.length > 5 && | ||
inspectedValue.isBlock() && | ||
inspectedValue.isMultiline() | ||
) { | ||
this.indentLines(); | ||
@@ -134,10 +176,9 @@ this.nl().i(); | ||
// Intended to be redefined by a plugin that offers syntax highlighting: | ||
expect.addStyle('code', function (content, language) { | ||
expect.addStyle('code', function(content, language) { | ||
this.text(content); | ||
}); | ||
expect.addStyle('annotationBlock', function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
expect.addStyle('annotationBlock', function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
@@ -147,3 +188,3 @@ var pen = this.getContentFromArguments(args); | ||
this.block(function () { | ||
this.block(function() { | ||
for (var i = 0; i < height; i += 1) { | ||
@@ -159,6 +200,5 @@ if (i > 0) { | ||
expect.addStyle('commentBlock', function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
expect.addStyle('commentBlock', function() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
@@ -168,3 +208,3 @@ var pen = this.getContentFromArguments(args); | ||
this.block(function () { | ||
this.block(function() { | ||
for (var i = 0; i < height; i += 1) { | ||
@@ -180,8 +220,10 @@ if (i > 0) { | ||
expect.addStyle('removedHighlight', function (content) { | ||
expect.addStyle('removedHighlight', function(content) { | ||
this.alt({ | ||
text: function text() { | ||
content.split(/(\n)/).forEach(function (fragment) { | ||
this.block(function () { | ||
this.text(fragment.replace(/\n/g, '\\n')).nl().text(fragment.replace(/[\s\S]/g, '^')); | ||
content.split(/(\n)/).forEach(function(fragment) { | ||
this.block(function() { | ||
this.text(fragment.replace(/\n/g, '\\n')) | ||
.nl() | ||
.text(fragment.replace(/[\s\S]/g, '^')); | ||
}); | ||
@@ -194,9 +236,9 @@ if (fragment === '\n') { | ||
fallback: function fallback() { | ||
var _this = this; | ||
var this$1 = this; | ||
content.split(/(\n)/).forEach(function (fragment) { | ||
if (fragment === '\n') { | ||
_this.diffRemovedSpecialChar('\\n').nl(); | ||
this$1.diffRemovedSpecialChar('\\n').nl(); | ||
} else { | ||
_this.diffRemovedHighlight(fragment); | ||
this$1.diffRemovedHighlight(fragment); | ||
} | ||
@@ -208,11 +250,13 @@ }); | ||
expect.addStyle('match', function (content) { | ||
expect.addStyle('match', function(content) { | ||
this.alt({ | ||
text: function text() { | ||
content.split(/(\n)/).forEach(function (fragment) { | ||
content.split(/(\n)/).forEach(function(fragment) { | ||
if (fragment === '\n') { | ||
this.nl(); | ||
} else { | ||
this.block(function () { | ||
this.text(fragment).nl().text(fragment.replace(/[\s\S]/g, '^')); | ||
this.block(function() { | ||
this.text(fragment) | ||
.nl() | ||
.text(fragment.replace(/[\s\S]/g, '^')); | ||
}); | ||
@@ -228,3 +272,3 @@ } | ||
expect.addStyle('partialMatch', function (content) { | ||
expect.addStyle('partialMatch', function(content) { | ||
this.alt({ | ||
@@ -241,11 +285,13 @@ text: function text() { | ||
expect.addStyle('shouldEqualError', function (expected) { | ||
this.error(typeof expected === 'undefined' ? 'should be' : 'should equal').sp().block(function () { | ||
this.appendInspected(expected); | ||
}); | ||
expect.addStyle('shouldEqualError', function(expected) { | ||
this.error(typeof expected === 'undefined' ? 'should be' : 'should equal') | ||
.sp() | ||
.block(function() { | ||
this.appendInspected(expected); | ||
}); | ||
}); | ||
expect.addStyle('errorName', function (_ref) { | ||
var name = _ref.name, | ||
constructor = _ref.constructor; | ||
expect.addStyle('errorName', function(ref) { | ||
var name = ref.name; | ||
var constructor = ref.constructor; | ||
@@ -261,5 +307,7 @@ if (typeof name === 'string' && name !== 'Error') { | ||
expect.addStyle('appendErrorMessage', function (error, options) { | ||
expect.addStyle('appendErrorMessage', function(error, options) { | ||
if (error && error.isUnexpected) { | ||
this.append(error.getErrorMessage(utils.extend({ output: this }, options))); | ||
this.append( | ||
error.getErrorMessage(utils.extend({ output: this }, options)) | ||
); | ||
} else { | ||
@@ -270,3 +318,3 @@ this.appendInspected(error); | ||
expect.addStyle('appendItems', function (items, separator) { | ||
expect.addStyle('appendItems', function(items, separator) { | ||
var that = this; | ||
@@ -282,5 +330,10 @@ separator = separator || ''; | ||
expect.addStyle('stringDiffFragment', function (ch, text, baseStyle, markUpSpecialCharacters) { | ||
text.split(/\n/).forEach(function (line, i, _ref2) { | ||
var length = _ref2.length; | ||
expect.addStyle('stringDiffFragment', function( | ||
ch, | ||
text, | ||
baseStyle, | ||
markUpSpecialCharacters | ||
) { | ||
text.split(/\n/).forEach(function(line, i, ref) { | ||
var length = ref.length; | ||
@@ -292,3 +345,5 @@ if (this.isAtStartOfLine()) { | ||
if (line === '' && ch !== ' ' && (i === 0 || i !== length - 1)) { | ||
this[ch === '+' ? 'diffAddedSpecialChar' : 'diffRemovedSpecialChar']('\\n'); | ||
this[ | ||
ch === '+' ? 'diffAddedSpecialChar' : 'diffRemovedSpecialChar' | ||
]('\\n'); | ||
} | ||
@@ -304,5 +359,9 @@ } | ||
if (markUpSpecialCharacters) { | ||
line.split(specialCharRegExp).forEach(function (part) { | ||
line.split(specialCharRegExp).forEach(function(part) { | ||
if (specialCharRegExp.test(part)) { | ||
this[{ '+': 'diffAddedSpecialChar', '-': 'diffRemovedSpecialChar' }[ch] || baseStyle](utils.escapeChar(part)); | ||
this[ | ||
{ '+': 'diffAddedSpecialChar', '-': 'diffRemovedSpecialChar' }[ | ||
ch | ||
] || baseStyle | ||
](utils.escapeChar(part)); | ||
} else { | ||
@@ -316,3 +375,6 @@ this[baseStyle](part); | ||
if (matchTrailingSpace) { | ||
this[{ '+': 'diffAddedHighlight', '-': 'diffRemovedHighlight' }[ch] || baseStyle](matchTrailingSpace[2]); | ||
this[ | ||
{ '+': 'diffAddedHighlight', '-': 'diffRemovedHighlight' }[ch] || | ||
baseStyle | ||
](matchTrailingSpace[2]); | ||
} | ||
@@ -325,8 +387,8 @@ if (i !== length - 1) { | ||
expect.addStyle('stringDiff', function (actual, expected) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
expect.addStyle('stringDiff', function(actual, expected, options) { | ||
if ( options === void 0 ) options = {}; | ||
var type = options.type || 'WordsWithSpace'; | ||
var diffLines = []; | ||
var lastPart = void 0; | ||
var lastPart; | ||
stringDiff.diffLines(actual, expected).forEach(function (part) { | ||
@@ -351,3 +413,3 @@ if (lastPart && lastPart.removed && part.added) { | ||
diffLines.forEach(function (part, index) { | ||
diffLines.forEach(function(part, index) { | ||
if (part.replaced) { | ||
@@ -365,11 +427,21 @@ var oldValue = part.oldValue; | ||
} | ||
stringDiff['diff' + type](oldValue, newValue).forEach(function (_ref3) { | ||
var added = _ref3.added, | ||
value = _ref3.value, | ||
removed = _ref3.removed; | ||
stringDiff[("diff" + type)](oldValue, newValue).forEach(function(ref) { | ||
var added = ref.added; | ||
var value = ref.value; | ||
var removed = ref.removed; | ||
if (added) { | ||
newLine.stringDiffFragment('+', value, 'diffAddedHighlight', options.markUpSpecialCharacters); | ||
newLine.stringDiffFragment( | ||
'+', | ||
value, | ||
'diffAddedHighlight', | ||
options.markUpSpecialCharacters | ||
); | ||
} else if (removed) { | ||
this.stringDiffFragment('-', value, 'diffRemovedHighlight', options.markUpSpecialCharacters); | ||
this.stringDiffFragment( | ||
'-', | ||
value, | ||
'diffRemovedHighlight', | ||
options.markUpSpecialCharacters | ||
); | ||
} else { | ||
@@ -379,3 +451,4 @@ newLine.stringDiffFragment('+', value, 'diffAddedLine'); | ||
} | ||
}, this); | ||
}, | ||
this); | ||
if (newEndsWithNewline && !oldEndsWithNewline) { | ||
@@ -388,3 +461,5 @@ newLine.diffAddedSpecialChar('\\n'); | ||
} | ||
this.nl().append(newLine).nl(oldEndsWithNewline && index < diffLines.length - 1 ? 1 : 0); | ||
this.nl() | ||
.append(newLine) | ||
.nl(oldEndsWithNewline && index < diffLines.length - 1 ? 1 : 0); | ||
} else { | ||
@@ -394,5 +469,15 @@ var endsWithNewline = /\n$/.test(part.value); | ||
if (part.added) { | ||
this.stringDiffFragment('+', value, 'diffAddedLine', options.markUpSpecialCharacters); | ||
this.stringDiffFragment( | ||
'+', | ||
value, | ||
'diffAddedLine', | ||
options.markUpSpecialCharacters | ||
); | ||
} else if (part.removed) { | ||
this.stringDiffFragment('-', value, 'diffRemovedLine', options.markUpSpecialCharacters); | ||
this.stringDiffFragment( | ||
'-', | ||
value, | ||
'diffRemovedLine', | ||
options.markUpSpecialCharacters | ||
); | ||
} else { | ||
@@ -408,18 +493,28 @@ this.stringDiffFragment(' ', value, 'text'); | ||
expect.addStyle('arrow', function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
expect.addStyle('arrow', function(options) { | ||
if ( options === void 0 ) options = {}; | ||
var styles = options.styles || []; | ||
var i = void 0; | ||
this.nl(options.top || 0).sp(options.left || 0).text('┌', styles); | ||
var i; | ||
this.nl(options.top || 0) | ||
.sp(options.left || 0) | ||
.text('┌', styles); | ||
for (i = 1; i < options.width; i += 1) { | ||
this.text(i === options.width - 1 && options.direction === 'up' ? '▷' : '─', styles); | ||
this.text( | ||
i === options.width - 1 && options.direction === 'up' ? '▷' : '─', | ||
styles | ||
); | ||
} | ||
this.nl(); | ||
for (i = 1; i < options.height - 1; i += 1) { | ||
this.sp(options.left || 0).text('│', styles).nl(); | ||
this.sp(options.left || 0) | ||
.text('│', styles) | ||
.nl(); | ||
} | ||
this.sp(options.left || 0).text('└', styles); | ||
for (i = 1; i < options.width; i += 1) { | ||
this.text(i === options.width - 1 && options.direction === 'down' ? '▷' : '─', styles); | ||
this.text( | ||
i === options.width - 1 && options.direction === 'down' ? '▷' : '─', | ||
styles | ||
); | ||
} | ||
@@ -429,11 +524,18 @@ }); | ||
var flattenBlocksInLines = require('magicpen/lib/flattenBlocksInLines'); | ||
expect.addStyle('merge', function (pens) { | ||
var flattenedPens = pens.map(function (_ref4) { | ||
var output = _ref4.output; | ||
return flattenBlocksInLines(output); | ||
}).reverse(); | ||
var maxHeight = flattenedPens.reduce(function (maxHeight, _ref5) { | ||
var length = _ref5.length; | ||
return Math.max(maxHeight, length); | ||
}, 0); | ||
expect.addStyle('merge', function(pens) { | ||
var flattenedPens = pens | ||
.map(function (ref) { | ||
var output = ref.output; | ||
return flattenBlocksInLines(output); | ||
}) | ||
.reverse(); | ||
var maxHeight = flattenedPens.reduce( | ||
function (maxHeight, ref) { | ||
var length = ref.length; | ||
return Math.max(maxHeight, length); | ||
}, | ||
0 | ||
); | ||
var blockNumbers = new Array(flattenedPens.length); | ||
@@ -446,3 +548,3 @@ var blockOffsets = new Array(flattenedPens.length); | ||
} | ||
var i = void 0; | ||
var i = (void 0); | ||
for (i = 0; i < blockNumbers.length; i += 1) { | ||
@@ -452,3 +554,3 @@ blockNumbers[i] = 0; | ||
} | ||
var contentLeft = void 0; | ||
var contentLeft = (void 0); | ||
do { | ||
@@ -460,3 +562,7 @@ contentLeft = false; | ||
if (currentLine) { | ||
while (currentLine[blockNumbers[i]] && blockOffsets[i] >= currentLine[blockNumbers[i]].args.content.length) { | ||
while ( | ||
currentLine[blockNumbers[i]] && | ||
blockOffsets[i] >= | ||
currentLine[blockNumbers[i]].args.content.length | ||
) { | ||
blockNumbers[i] += 1; | ||
@@ -486,3 +592,6 @@ blockOffsets[i] = 0; | ||
expect.addStyle('arrowsAlongsideChangeOutputs', function (packing, changeOutputs) { | ||
expect.addStyle('arrowsAlongsideChangeOutputs', function( | ||
packing, | ||
changeOutputs | ||
) { | ||
if (packing) { | ||
@@ -498,17 +607,19 @@ var topByChangeNumber = {}; | ||
var arrows = []; | ||
packing.forEach(function (columnSet, i, _ref6) { | ||
var length = _ref6.length; | ||
packing.forEach(function (columnSet, i, ref) { | ||
var length = ref.length; | ||
columnSet.forEach(function (_ref7) { | ||
var start = _ref7.start, | ||
end = _ref7.end, | ||
direction = _ref7.direction; | ||
columnSet.forEach(function (ref) { | ||
var start = ref.start; | ||
var end = ref.end; | ||
var direction = ref.direction; | ||
arrows.push(that.clone().arrow({ | ||
left: i * 2, | ||
top: topByChangeNumber[start], | ||
width: 1 + (length - i) * 2, | ||
height: topByChangeNumber[end] - topByChangeNumber[start] + 1, | ||
direction: direction | ||
})); | ||
arrows.push( | ||
that.clone().arrow({ | ||
left: i * 2, | ||
top: topByChangeNumber[start], | ||
width: 1 + (length - i) * 2, | ||
height: topByChangeNumber[end] - topByChangeNumber[start] + 1, | ||
direction: direction | ||
}) | ||
); | ||
}); | ||
@@ -520,3 +631,3 @@ }); | ||
} else if (arrows.length > 1) { | ||
this.block(function () { | ||
this.block(function() { | ||
this.merge(arrows); | ||
@@ -529,4 +640,4 @@ }); | ||
this.block(function () { | ||
changeOutputs.forEach(function (changeOutput, index) { | ||
this.block(function() { | ||
changeOutputs.forEach(function(changeOutput, index) { | ||
this.nl(index > 0 ? 1 : 0); | ||
@@ -539,2 +650,2 @@ if (!changeOutput.isEmpty()) { | ||
}); | ||
}; | ||
}; |
@@ -11,2 +11,2 @@ function throwIfNonUnexpectedError(err) { | ||
module.exports = throwIfNonUnexpectedError; | ||
module.exports = throwIfNonUnexpectedError; |
@@ -1,11 +0,1 @@ | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var utils = require('./utils'); | ||
@@ -20,33 +10,46 @@ var isRegExp = utils.isRegExp; | ||
module.exports = function (expect) { | ||
module.exports = function(expect) { | ||
expect.addType({ | ||
name: 'wrapperObject', | ||
identify: false, | ||
equal: function equal(a, b, _equal) { | ||
return a === b || _equal(this.unwrap(a), this.unwrap(b)); | ||
equal: function equal(a, b, equal$1) { | ||
return a === b || equal$1(this.unwrap(a), this.unwrap(b)); | ||
}, | ||
inspect: function inspect(value, depth, output, _inspect) { | ||
inspect: function inspect(value, depth, output, inspect$1) { | ||
output.append(this.prefix(output.clone(), value)); | ||
output.append(_inspect(this.unwrap(value), depth)); | ||
output.append(inspect$1(this.unwrap(value), depth)); | ||
output.append(this.suffix(output.clone(), value)); | ||
return output; | ||
}, | ||
diff: function diff(actual, expected, output, _diff, inspect) { | ||
diff: function diff(actual, expected, output, diff$1, inspect) { | ||
output.inline = true; | ||
actual = this.unwrap(actual); | ||
expected = this.unwrap(expected); | ||
var comparison = _diff(actual, expected); | ||
var comparison = diff$1(actual, expected); | ||
var prefixOutput = this.prefix(output.clone(), actual); | ||
var suffixOutput = this.suffix(output.clone(), actual); | ||
if (comparison && comparison.inline) { | ||
return output.append(prefixOutput).append(comparison).append(suffixOutput); | ||
return output | ||
.append(prefixOutput) | ||
.append(comparison) | ||
.append(suffixOutput); | ||
} else { | ||
return output.append(prefixOutput).nl().indentLines().i().block(function () { | ||
this.append(inspect(actual)).sp().annotationBlock(function () { | ||
this.shouldEqualError(expected, inspect); | ||
if (comparison) { | ||
this.nl(2).append(comparison); | ||
} | ||
}); | ||
}).nl().outdentLines().append(suffixOutput); | ||
return output | ||
.append(prefixOutput) | ||
.nl() | ||
.indentLines() | ||
.i() | ||
.block(function() { | ||
this.append(inspect(actual)) | ||
.sp() | ||
.annotationBlock(function() { | ||
this.shouldEqualError(expected, inspect); | ||
if (comparison) { | ||
this.nl(2).append(comparison); | ||
} | ||
}); | ||
}) | ||
.nl() | ||
.outdentLines() | ||
.append(suffixOutput); | ||
} | ||
@@ -60,6 +63,10 @@ } | ||
identify: function identify(obj) { | ||
return (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) === 'symbol'; | ||
return typeof obj === 'symbol'; | ||
}, | ||
inspect: function inspect(obj, depth, output, _inspect2) { | ||
return output.jsKeyword('Symbol').text('(').singleQuotedString(obj.toString().replace(/^Symbol\(|\)$/g, '')).text(')'); | ||
inspect: function inspect(obj, depth, output, inspect$1) { | ||
return output | ||
.jsKeyword('Symbol') | ||
.text('(') | ||
.singleQuotedString(obj.toString().replace(/^Symbol\(|\)$/g, '')) | ||
.text(')'); | ||
} | ||
@@ -74,9 +81,13 @@ }); | ||
identify: function identify(obj) { | ||
return obj && (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) === 'object'; | ||
return obj && typeof obj === 'object'; | ||
}, | ||
prefix: function prefix(output, obj) { | ||
var constructor = obj.constructor; | ||
var constructorName = constructor && typeof constructor === 'function' && constructor !== Object && utils.getFunctionName(constructor); | ||
var constructorName = | ||
constructor && | ||
typeof constructor === 'function' && | ||
constructor !== Object && | ||
utils.getFunctionName(constructor); | ||
if (constructorName && constructorName !== 'Object') { | ||
output.text(constructorName + '('); | ||
output.text((constructorName + "(")); | ||
} | ||
@@ -91,3 +102,7 @@ return output.text('{'); | ||
var constructor = obj.constructor; | ||
var constructorName = constructor && typeof constructor === 'function' && constructor !== Object && utils.getFunctionName(constructor); | ||
var constructorName = | ||
constructor && | ||
typeof constructor === 'function' && | ||
constructor !== Object && | ||
utils.getFunctionName(constructor); | ||
if (constructorName && constructorName !== 'Object') { | ||
@@ -104,42 +119,45 @@ output.text(')'); | ||
}, | ||
getKeys: Object.getOwnPropertySymbols ? function (obj) { | ||
var keys = Object.getOwnPropertyNames(obj); | ||
var symbols = Object.getOwnPropertySymbols(obj); | ||
if (symbols.length > 0) { | ||
return keys.concat(symbols); | ||
} else { | ||
return keys; | ||
} | ||
} : Object.getOwnPropertyNames, | ||
getKeys: Object.getOwnPropertySymbols | ||
? function (obj) { | ||
var keys = Object.getOwnPropertyNames(obj); | ||
var symbols = Object.getOwnPropertySymbols(obj); | ||
if (symbols.length > 0) { | ||
return keys.concat(symbols); | ||
} else { | ||
return keys; | ||
} | ||
} | ||
: Object.getOwnPropertyNames, | ||
// If Symbol support is not detected default to undefined which, when | ||
// passed to Array.prototype.sort, means "natural" (asciibetical) sort. | ||
keyComparator: typeof Symbol === 'function' ? function (a, b) { | ||
var aIsSymbol = void 0, | ||
bIsSymbol = void 0; | ||
var aString = a; | ||
var bString = b; | ||
aIsSymbol = (typeof a === 'undefined' ? 'undefined' : (0, _typeof3.default)(a)) === 'symbol'; | ||
bIsSymbol = (typeof b === 'undefined' ? 'undefined' : (0, _typeof3.default)(b)) === 'symbol'; | ||
if (aIsSymbol) { | ||
if (bIsSymbol) { | ||
aString = a.toString(); | ||
bString = b.toString(); | ||
} else { | ||
return 1; | ||
} | ||
} else if (bIsSymbol) { | ||
return -1; | ||
} | ||
keyComparator: | ||
typeof Symbol === 'function' | ||
? function (a, b) { | ||
var aIsSymbol, bIsSymbol; | ||
var aString = a; | ||
var bString = b; | ||
aIsSymbol = typeof a === 'symbol'; | ||
bIsSymbol = typeof b === 'symbol'; | ||
if (aIsSymbol) { | ||
if (bIsSymbol) { | ||
aString = a.toString(); | ||
bString = b.toString(); | ||
} else { | ||
return 1; | ||
} | ||
} else if (bIsSymbol) { | ||
return -1; | ||
} | ||
if (aString < bString) { | ||
return -1; | ||
} else if (aString > bString) { | ||
return 1; | ||
} | ||
if (aString < bString) { | ||
return -1; | ||
} else if (aString > bString) { | ||
return 1; | ||
} | ||
return 0; | ||
} : undefined, | ||
equal: function equal(a, b, _equal2) { | ||
return utils.checkObjectEqualityUsingType(a, b, this, _equal2); | ||
return 0; | ||
} | ||
: undefined, | ||
equal: function equal(a, b, equal$1) { | ||
return utils.checkObjectEqualityUsingType(a, b, this, equal$1); | ||
}, | ||
@@ -153,3 +171,3 @@ hasKey: function hasKey(obj, key, own) { | ||
}, | ||
inspect: function inspect(obj, depth, output, _inspect3) { | ||
inspect: function inspect(obj, depth, output, inspect$1) { | ||
var keys = this.getKeys(obj); | ||
@@ -163,3 +181,5 @@ if (keys.length === 0) { | ||
var inspectedItems = keys.map(function (key, index) { | ||
var propertyDescriptor = Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(obj, key); | ||
var propertyDescriptor = | ||
Object.getOwnPropertyDescriptor && | ||
Object.getOwnPropertyDescriptor(obj, key); | ||
var hasGetter = propertyDescriptor && propertyDescriptor.get; | ||
@@ -172,3 +192,3 @@ var hasSetter = propertyDescriptor && propertyDescriptor.set; | ||
// Inspect the setter function if there's no getter: | ||
var value = void 0; | ||
var value; | ||
if (hasSetter && !hasGetter) { | ||
@@ -180,3 +200,3 @@ value = hasSetter; | ||
var inspectedValue = _inspect3(value); | ||
var inspectedValue = inspect$1(value); | ||
if (value && value._expectIt) { | ||
@@ -187,3 +207,5 @@ inspectedValue = output.clone().block(inspectedValue); | ||
propertyOutput.amend(type.delimiter(output.clone(), index, keys.length)); | ||
propertyOutput.amend( | ||
type.delimiter(output.clone(), index, keys.length) | ||
); | ||
@@ -199,11 +221,14 @@ if (hasGetter && hasSetter) { | ||
var maxLineLength = output.preferredWidth - (depth === Infinity ? 0 : depth) * 2 - 2; | ||
var maxLineLength = | ||
output.preferredWidth - (depth === Infinity ? 0 : depth) * 2 - 2; | ||
var width = 0; | ||
var compact = inspectedItems.length > 5 || inspectedItems.every(function (inspectedItem) { | ||
if (inspectedItem.isMultiline()) { | ||
return false; | ||
} | ||
width += inspectedItem.size().width; | ||
return width < maxLineLength; | ||
}); | ||
var compact = | ||
inspectedItems.length > 5 || | ||
inspectedItems.every(function (inspectedItem) { | ||
if (inspectedItem.isMultiline()) { | ||
return false; | ||
} | ||
width += inspectedItem.size().width; | ||
return width < maxLineLength; | ||
}); | ||
@@ -258,9 +283,23 @@ var itemsOutput = output.clone(); | ||
} else { | ||
output.sp(prefixOutput.isEmpty() ? 0 : 1).append(itemsOutput).sp(suffixOutput.isEmpty() ? 0 : 1); | ||
output | ||
.sp(prefixOutput.isEmpty() ? 0 : 1) | ||
.append(itemsOutput) | ||
.sp(suffixOutput.isEmpty() ? 0 : 1); | ||
} | ||
return output.append(suffixOutput); | ||
}, | ||
diff: function diff(actual, expected, output, _diff2, inspect, equal) { | ||
diff: function diff(actual, expected, output, diff$1, inspect, equal) { | ||
if (actual.constructor !== expected.constructor) { | ||
return output.text('Mismatching constructors ').text(actual.constructor && utils.getFunctionName(actual.constructor) || actual.constructor).text(' should be ').text(expected.constructor && utils.getFunctionName(expected.constructor) || expected.constructor); | ||
return output | ||
.text('Mismatching constructors ') | ||
.text( | ||
(actual.constructor && utils.getFunctionName(actual.constructor)) || | ||
actual.constructor | ||
) | ||
.text(' should be ') | ||
.text( | ||
(expected.constructor && | ||
utils.getFunctionName(expected.constructor)) || | ||
expected.constructor | ||
); | ||
} | ||
@@ -280,46 +319,51 @@ | ||
keys.forEach(function (key, index) { | ||
output.nl(index > 0 ? 1 : 0).i().block(function () { | ||
var valueActual = type.valueForKey(actual, key); | ||
var valueExpected = type.valueForKey(expected, key); | ||
var annotation = output.clone(); | ||
var conflicting = !equal(valueActual, valueExpected); | ||
var isInlineDiff = false; | ||
var valueOutput = void 0; | ||
if (conflicting) { | ||
if (!type.hasKey(expected, key)) { | ||
annotation.error('should be removed'); | ||
isInlineDiff = true; | ||
} else if (!type.hasKey(actual, key)) { | ||
this.error('// missing').sp(); | ||
valueOutput = output.clone().appendInspected(valueExpected); | ||
isInlineDiff = true; | ||
} else { | ||
var keyDiff = _diff2(valueActual, valueExpected); | ||
if (!keyDiff || keyDiff && !keyDiff.inline) { | ||
annotation.shouldEqualError(valueExpected); | ||
if (keyDiff) { | ||
annotation.nl(2).append(keyDiff); | ||
output | ||
.nl(index > 0 ? 1 : 0) | ||
.i() | ||
.block(function() { | ||
var valueActual = type.valueForKey(actual, key); | ||
var valueExpected = type.valueForKey(expected, key); | ||
var annotation = output.clone(); | ||
var conflicting = !equal(valueActual, valueExpected); | ||
var isInlineDiff = false; | ||
var valueOutput; | ||
if (conflicting) { | ||
if (!type.hasKey(expected, key)) { | ||
annotation.error('should be removed'); | ||
isInlineDiff = true; | ||
} else if (!type.hasKey(actual, key)) { | ||
this.error('// missing').sp(); | ||
valueOutput = output.clone().appendInspected(valueExpected); | ||
isInlineDiff = true; | ||
} else { | ||
var keyDiff = diff$1(valueActual, valueExpected); | ||
if (!keyDiff || (keyDiff && !keyDiff.inline)) { | ||
annotation.shouldEqualError(valueExpected); | ||
if (keyDiff) { | ||
annotation.nl(2).append(keyDiff); | ||
} | ||
} else { | ||
isInlineDiff = true; | ||
valueOutput = keyDiff; | ||
} | ||
} else { | ||
isInlineDiff = true; | ||
valueOutput = keyDiff; | ||
} | ||
} else { | ||
isInlineDiff = true; | ||
} | ||
} else { | ||
isInlineDiff = true; | ||
} | ||
if (!valueOutput) { | ||
valueOutput = inspect(valueActual, conflicting ? Infinity : null); | ||
} | ||
if (!valueOutput) { | ||
valueOutput = inspect(valueActual, conflicting ? Infinity : null); | ||
} | ||
valueOutput.amend(type.delimiter(output.clone(), index, actualKeys.length)); | ||
if (!isInlineDiff) { | ||
valueOutput = output.clone().block(valueOutput); | ||
} | ||
type.property(this, key, valueOutput); | ||
if (!annotation.isEmpty()) { | ||
this.sp().annotationBlock(annotation); | ||
} | ||
}); | ||
valueOutput.amend( | ||
type.delimiter(output.clone(), index, actualKeys.length) | ||
); | ||
if (!isInlineDiff) { | ||
valueOutput = output.clone().block(valueOutput); | ||
} | ||
type.property(this, key, valueOutput); | ||
if (!annotation.isEmpty()) { | ||
this.sp().annotationBlock(annotation); | ||
} | ||
}); | ||
}); | ||
@@ -334,3 +378,3 @@ | ||
similar: function similar(a, b) { | ||
var _this = this; | ||
var this$1 = this; | ||
@@ -341,4 +385,4 @@ if (a === null || b === null) { | ||
var typeA = typeof a === 'undefined' ? 'undefined' : (0, _typeof3.default)(a); | ||
var typeB = typeof b === 'undefined' ? 'undefined' : (0, _typeof3.default)(b); | ||
var typeA = typeof a; | ||
var typeB = typeof b; | ||
@@ -364,5 +408,7 @@ if (typeA !== typeB) { | ||
var numberOfSimilarKeys = 0; | ||
var requiredSimilarKeys = Math.round(Math.max(aKeys.length, bKeys.length) / 2); | ||
var requiredSimilarKeys = Math.round( | ||
Math.max(aKeys.length, bKeys.length) / 2 | ||
); | ||
return aKeys.concat(bKeys).some(function (key) { | ||
if (_this.hasKey(a, key) && _this.hasKey(b, key)) { | ||
if (this$1.hasKey(a, key) && this$1.hasKey(b, key)) { | ||
numberOfSimilarKeys += 1; | ||
@@ -373,3 +419,2 @@ } | ||
}, | ||
uniqueKeys: utils.uniqueStringsAndSymbols, | ||
@@ -387,4 +432,4 @@ valueForKey: function valueForKey(obj, key) { | ||
}, | ||
inspect: function inspect(_ref, depth, output) { | ||
var name = _ref.name; | ||
inspect: function inspect(ref, depth, output) { | ||
var name = ref.name; | ||
@@ -406,30 +451,31 @@ return output.text('type: ').jsKeyword(name); | ||
if (!this.numericalPropertiesOnly) { | ||
keys.push.apply(keys, (0, _toConsumableArray3.default)(this.getKeysNonNumerical(obj))); | ||
keys.push.apply(keys, this.getKeysNonNumerical(obj)); | ||
} | ||
return keys; | ||
}, | ||
getKeysNonNumerical: Object.getOwnPropertySymbols ? function (obj) { | ||
var keys = []; | ||
Object.keys(obj).forEach(function (key) { | ||
if (!utils.numericalRegExp.test(key)) { | ||
keys.push(key); | ||
getKeysNonNumerical: Object.getOwnPropertySymbols | ||
? function (obj) { | ||
var keys = []; | ||
Object.keys(obj).forEach(function (key) { | ||
if (!utils.numericalRegExp.test(key)) { | ||
keys.push(key); | ||
} | ||
}); | ||
var symbols = Object.getOwnPropertySymbols(obj); | ||
if (symbols.length > 0) { | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
}); | ||
var symbols = Object.getOwnPropertySymbols(obj); | ||
if (symbols.length > 0) { | ||
keys.push.apply(keys, (0, _toConsumableArray3.default)(symbols)); | ||
} | ||
return keys; | ||
} : function (obj) { | ||
var keys = []; | ||
Object.keys(obj).forEach(function (key) { | ||
if (!utils.numericalRegExp.test(key)) { | ||
keys.push(key); | ||
} | ||
}); | ||
return keys; | ||
}, | ||
equal: function equal(a, b, _equal3) { | ||
var _this2 = this; | ||
: function (obj) { | ||
var keys = []; | ||
Object.keys(obj).forEach(function (key) { | ||
if (!utils.numericalRegExp.test(key)) { | ||
keys.push(key); | ||
} | ||
}); | ||
return keys; | ||
}, | ||
equal: function equal(a, b, equal$1) { | ||
var this$1 = this; | ||
@@ -439,7 +485,7 @@ if (a === b) { | ||
} else if (a.constructor === b.constructor && a.length === b.length) { | ||
var i = void 0; | ||
var i; | ||
// compare numerically indexed elements | ||
for (i = 0; i < a.length; i += 1) { | ||
if (!_equal3(this.valueForKey(a, i), this.valueForKey(b, i))) { | ||
if (!equal$1(this.valueForKey(a, i), this.valueForKey(b, i))) { | ||
return false; | ||
@@ -453,7 +499,10 @@ } | ||
// include keys whose value is not undefined | ||
return typeof _this2.valueForKey(a, key) !== 'undefined'; | ||
return typeof this$1.valueForKey(a, key) !== 'undefined'; | ||
}); | ||
var bKeys = this.getKeysNonNumerical(b).filter(function (key) { | ||
// include keys whose value is not undefined on either LHS or RHS | ||
return typeof _this2.valueForKey(b, key) !== 'undefined' || typeof _this2.valueForKey(a, key) !== 'undefined'; | ||
return ( | ||
typeof this$1.valueForKey(b, key) !== 'undefined' || | ||
typeof this$1.valueForKey(a, key) !== 'undefined' | ||
); | ||
}); | ||
@@ -466,3 +515,8 @@ | ||
for (i = 0; i < aKeys.length; i += 1) { | ||
if (!_equal3(this.valueForKey(a, aKeys[i]), this.valueForKey(b, bKeys[i]))) { | ||
if ( | ||
!equal$1( | ||
this.valueForKey(a, aKeys[i]), | ||
this.valueForKey(b, bKeys[i]) | ||
) | ||
) { | ||
return false; | ||
@@ -484,4 +538,4 @@ } | ||
}, | ||
inspect: function inspect(arr, depth, output, _inspect4) { | ||
var _this3 = this; | ||
inspect: function inspect(arr, depth, output, inspect$1) { | ||
var this$1 = this; | ||
@@ -496,9 +550,12 @@ var prefixOutput = this.prefix(output.clone(), arr); | ||
if (depth === 1 && arr.length > 10) { | ||
return output.append(prefixOutput).text('...').append(suffixOutput); | ||
return output | ||
.append(prefixOutput) | ||
.text('...') | ||
.append(suffixOutput); | ||
} | ||
var inspectedItems = keys.map(function (key) { | ||
var inspectedValue = void 0; | ||
if (_this3.hasKey(arr, key)) { | ||
inspectedValue = _inspect4(_this3.valueForKey(arr, key)); | ||
var inspectedValue; | ||
if (this$1.hasKey(arr, key)) { | ||
inspectedValue = inspect$1(this$1.valueForKey(arr, key)); | ||
} else if (utils.numericalRegExp.test(key)) { | ||
@@ -509,21 +566,24 @@ // Sparse array entry | ||
// Not present non-numerical property returned by getKeys | ||
inspectedValue = _inspect4(undefined); | ||
inspectedValue = inspect$1(undefined); | ||
} | ||
return _this3.property(output.clone(), key, inspectedValue, true); | ||
return this$1.property(output.clone(), key, inspectedValue, true); | ||
}); | ||
var currentDepth = defaultDepth - Math.min(defaultDepth, depth); | ||
var maxLineLength = output.preferredWidth - 20 - currentDepth * output.indentationWidth - 2; | ||
var maxLineLength = | ||
output.preferredWidth - 20 - currentDepth * output.indentationWidth - 2; | ||
var width = 0; | ||
var multipleLines = this.forceMultipleLines || inspectedItems.some(function (o) { | ||
if (o.isMultiline()) { | ||
return true; | ||
} | ||
var multipleLines = | ||
this.forceMultipleLines || | ||
inspectedItems.some(function (o) { | ||
if (o.isMultiline()) { | ||
return true; | ||
} | ||
var size = o.size(); | ||
width += size.width; | ||
return width > maxLineLength; | ||
}); | ||
var size = o.size(); | ||
width += size.width; | ||
return width > maxLineLength; | ||
}); | ||
inspectedItems.forEach(function (inspectedItem, index) { | ||
inspectedItem.amend(_this3.delimiter(output.clone(), index, keys.length)); | ||
inspectedItem.amend(this$1.delimiter(output.clone(), index, keys.length)); | ||
}); | ||
@@ -539,3 +599,6 @@ if (multipleLines) { | ||
inspectedItems.forEach(function (inspectedItem, index) { | ||
output.nl(index > 0 ? 1 : 0).i().block(inspectedItem); | ||
output | ||
.nl(index > 0 ? 1 : 0) | ||
.i() | ||
.block(inspectedItem); | ||
}); | ||
@@ -564,9 +627,8 @@ | ||
}, | ||
diffLimit: 512, | ||
diff: function diff(actual, expected, output, _diff3, inspect, equal) { | ||
diff: function diff(actual, expected, output, diff$1, inspect, equal) { | ||
output.inline = true; | ||
if (Math.max(actual.length, expected.length) > this.diffLimit) { | ||
output.jsComment('Diff suppressed due to size > ' + this.diffLimit); | ||
output.jsComment(("Diff suppressed due to size > " + (this.diffLimit))); | ||
return output; | ||
@@ -590,60 +652,111 @@ } | ||
var expectedKeys = this.getKeys(expected); | ||
var nonNumericalKeysAndSymbols = !this.numericalPropertiesOnly && utils.uniqueNonNumericalStringsAndSymbols(actualKeys, expectedKeys); | ||
var nonNumericalKeysAndSymbols = | ||
!this.numericalPropertiesOnly && | ||
utils.uniqueNonNumericalStringsAndSymbols(actualKeys, expectedKeys); | ||
var type = this; | ||
var changes = arrayChanges(actualElements, expectedElements, equal, function (a, b) { | ||
return type.similar(a, b); | ||
}, { | ||
includeNonNumericalProperties: nonNumericalKeysAndSymbols | ||
}); | ||
var indexOfLastNonInsert = changes.reduce(function (previousValue, diffItem, index) { | ||
return diffItem.type === 'insert' ? previousValue : index; | ||
}, -1); | ||
var changes = arrayChanges( | ||
actualElements, | ||
expectedElements, | ||
equal, | ||
function (a, b) { return type.similar(a, b); }, | ||
{ | ||
includeNonNumericalProperties: nonNumericalKeysAndSymbols | ||
} | ||
); | ||
var indexOfLastNonInsert = changes.reduce( | ||
function (previousValue, diffItem, index) { return diffItem.type === 'insert' ? previousValue : index; }, | ||
-1 | ||
); | ||
var packing = utils.packArrows(changes); // NOTE: Will have side effects in changes if the packing results in too many arrow lanes | ||
output.arrowsAlongsideChangeOutputs(packing, changes.map(function (diffItem, index) { | ||
var delimiterOutput = type.delimiter(output.clone(), index, indexOfLastNonInsert + 1); | ||
if (diffItem.type === 'moveTarget') { | ||
return output.clone(); | ||
} else { | ||
return output.clone().block(function () { | ||
if (diffItem.type === 'moveSource') { | ||
var propertyOutput = type.property(output.clone(), diffItem.actualIndex, inspect(diffItem.value), true); | ||
this.amend(propertyOutput).amend(delimiterOutput).sp().error('// should be moved'); | ||
} else if (diffItem.type === 'insert') { | ||
this.annotationBlock(function () { | ||
this.error('missing ').block(function () { | ||
var index = typeof diffItem.actualIndex !== 'undefined' ? diffItem.actualIndex : diffItem.expectedIndex; | ||
var propertyOutput = type.property(output.clone(), index, inspect(diffItem.value), true); | ||
this.amend(propertyOutput); | ||
output.arrowsAlongsideChangeOutputs( | ||
packing, | ||
changes.map(function (diffItem, index) { | ||
var delimiterOutput = type.delimiter( | ||
output.clone(), | ||
index, | ||
indexOfLastNonInsert + 1 | ||
); | ||
if (diffItem.type === 'moveTarget') { | ||
return output.clone(); | ||
} else { | ||
return output.clone().block(function() { | ||
if (diffItem.type === 'moveSource') { | ||
var propertyOutput = type.property( | ||
output.clone(), | ||
diffItem.actualIndex, | ||
inspect(diffItem.value), | ||
true | ||
); | ||
this.amend(propertyOutput) | ||
.amend(delimiterOutput) | ||
.sp() | ||
.error('// should be moved'); | ||
} else if (diffItem.type === 'insert') { | ||
this.annotationBlock(function() { | ||
this.error('missing ').block(function() { | ||
var index = | ||
typeof diffItem.actualIndex !== 'undefined' | ||
? diffItem.actualIndex | ||
: diffItem.expectedIndex; | ||
var propertyOutput = type.property( | ||
output.clone(), | ||
index, | ||
inspect(diffItem.value), | ||
true | ||
); | ||
this.amend(propertyOutput); | ||
}); | ||
}); | ||
}); | ||
} else if (diffItem.type === 'remove') { | ||
this.block(function () { | ||
var propertyOutput = type.property(output.clone(), diffItem.actualIndex, inspect(diffItem.value), true); | ||
this.amend(propertyOutput).amend(delimiterOutput).sp().error('// should be removed'); | ||
}); | ||
} else if (diffItem.type === 'equal') { | ||
this.block(function () { | ||
var propertyOutput = type.property(output.clone(), diffItem.actualIndex, inspect(diffItem.value), true); | ||
this.amend(propertyOutput).amend(delimiterOutput); | ||
}); | ||
} else { | ||
this.block(function () { | ||
var valueDiff = _diff3(diffItem.value, diffItem.expected); | ||
if (valueDiff && valueDiff.inline) { | ||
this.append(valueDiff).append(delimiterOutput); | ||
} else { | ||
var _propertyOutput = type.property(output.clone(), diffItem.actualIndex, inspect(diffItem.value), true); | ||
this.append(_propertyOutput).append(delimiterOutput).sp().annotationBlock(function () { | ||
this.shouldEqualError(diffItem.expected, inspect); | ||
if (valueDiff) { | ||
this.nl(2).append(valueDiff); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
})); | ||
} else if (diffItem.type === 'remove') { | ||
this.block(function() { | ||
var propertyOutput = type.property( | ||
output.clone(), | ||
diffItem.actualIndex, | ||
inspect(diffItem.value), | ||
true | ||
); | ||
this.amend(propertyOutput) | ||
.amend(delimiterOutput) | ||
.sp() | ||
.error('// should be removed'); | ||
}); | ||
} else if (diffItem.type === 'equal') { | ||
this.block(function() { | ||
var propertyOutput = type.property( | ||
output.clone(), | ||
diffItem.actualIndex, | ||
inspect(diffItem.value), | ||
true | ||
); | ||
this.amend(propertyOutput).amend(delimiterOutput); | ||
}); | ||
} else { | ||
this.block(function() { | ||
var valueDiff = diff$1(diffItem.value, diffItem.expected); | ||
if (valueDiff && valueDiff.inline) { | ||
this.append(valueDiff).append(delimiterOutput); | ||
} else { | ||
var propertyOutput = type.property( | ||
output.clone(), | ||
diffItem.actualIndex, | ||
inspect(diffItem.value), | ||
true | ||
); | ||
this.append(propertyOutput) | ||
.append(delimiterOutput) | ||
.sp() | ||
.annotationBlock(function() { | ||
this.shouldEqualError(diffItem.expected, inspect); | ||
if (valueDiff) { | ||
this.nl(2).append(valueDiff); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}) | ||
); | ||
@@ -682,3 +795,15 @@ if (this.indent) { | ||
var errorMethodBlacklist = ['message', 'name', 'description', 'line', 'number', 'column', 'sourceId', 'sourceURL', 'stack', 'stackArray', '__stackCleaned__', 'isOperational' // added by the promise implementation | ||
var errorMethodBlacklist = [ | ||
'message', | ||
'name', | ||
'description', | ||
'line', | ||
'number', | ||
'column', | ||
'sourceId', | ||
'sourceURL', | ||
'stack', | ||
'stackArray', | ||
'__stackCleaned__', | ||
'isOperational' // added by the promise implementation | ||
].reduce(function (result, prop) { | ||
@@ -702,5 +827,5 @@ result[prop] = true; | ||
getKeys: function getKeys(value) { | ||
var keys = this.baseType.getKeys(value).filter(function (key) { | ||
return !errorMethodBlacklist[key]; | ||
}); | ||
var keys = this.baseType | ||
.getKeys(value) | ||
.filter(function (key) { return !errorMethodBlacklist[key]; }); | ||
keys.unshift('message'); | ||
@@ -715,6 +840,10 @@ return keys; | ||
}, | ||
equal: function equal(a, b, _equal4) { | ||
return a === b || _equal4(a.message, b.message) && utils.checkObjectEqualityUsingType(a, b, this, _equal4); | ||
equal: function equal(a, b, equal$1) { | ||
return ( | ||
a === b || | ||
(equal$1(a.message, b.message) && | ||
utils.checkObjectEqualityUsingType(a, b, this, equal$1)) | ||
); | ||
}, | ||
inspect: function inspect(value, depth, output, _inspect5) { | ||
inspect: function inspect(value, depth, output, inspect$1) { | ||
output.errorName(value).text('('); | ||
@@ -724,17 +853,26 @@ var keys = this.getKeys(value); | ||
if (value.message !== '') { | ||
output.append(_inspect5(value.message)); | ||
output.append(inspect$1(value.message)); | ||
} | ||
} else { | ||
output.append(_inspect5(this.unwrap(value), depth)); | ||
output.append(inspect$1(this.unwrap(value), depth)); | ||
} | ||
return output.text(')'); | ||
}, | ||
diff: function diff(actual, expected, output, _diff4) { | ||
diff: function diff(actual, expected, output, diff$1) { | ||
if (actual.constructor !== expected.constructor) { | ||
return output.text('Mismatching constructors ').errorName(actual).text(' should be ').errorName(expected); | ||
return output | ||
.text('Mismatching constructors ') | ||
.errorName(actual) | ||
.text(' should be ') | ||
.errorName(expected); | ||
} | ||
output = _diff4(this.unwrap(actual), this.unwrap(expected)); | ||
output = diff$1(this.unwrap(actual), this.unwrap(expected)); | ||
if (output) { | ||
output = output.clone().errorName(actual).text('(').append(output).text(')'); | ||
output = output | ||
.clone() | ||
.errorName(actual) | ||
.text('(') | ||
.append(output) | ||
.text(')'); | ||
output.inline = false; | ||
@@ -746,3 +884,11 @@ } | ||
var unexpectedErrorMethodBlacklist = ['output', '_isUnexpected', 'htmlMessage', '_hasSerializedErrorMessage', 'expect', 'assertion', 'originalError'].reduce(function (result, prop) { | ||
var unexpectedErrorMethodBlacklist = [ | ||
'output', | ||
'_isUnexpected', | ||
'htmlMessage', | ||
'_hasSerializedErrorMessage', | ||
'expect', | ||
'assertion', | ||
'originalError' | ||
].reduce(function (result, prop) { | ||
result[prop] = true; | ||
@@ -755,8 +901,13 @@ return result; | ||
identify: function identify(value) { | ||
return value && (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === 'object' && value._isUnexpected && this.baseType.identify(value); | ||
return ( | ||
value && | ||
typeof value === 'object' && | ||
value._isUnexpected && | ||
this.baseType.identify(value) | ||
); | ||
}, | ||
getKeys: function getKeys(value) { | ||
return this.baseType.getKeys(value).filter(function (key) { | ||
return !unexpectedErrorMethodBlacklist[key]; | ||
}); | ||
return this.baseType | ||
.getKeys(value) | ||
.filter(function (key) { return !unexpectedErrorMethodBlacklist[key]; }); | ||
}, | ||
@@ -767,3 +918,8 @@ inspect: function inspect(value, depth, output) { | ||
if (errorMessage.isMultiline()) { | ||
output.nl().indentLines().i().block(errorMessage).nl(); | ||
output | ||
.nl() | ||
.indentLines() | ||
.i() | ||
.block(errorMessage) | ||
.nl(); | ||
} else { | ||
@@ -784,3 +940,3 @@ output.append(errorMessage); | ||
}, | ||
inspect: function inspect(date, depth, output, _inspect6) { | ||
inspect: function inspect(date, depth, output, inspect$1) { | ||
// TODO: Inspect "new" as an operator and Date as a built-in once we have the styles defined: | ||
@@ -792,8 +948,12 @@ var dateStr = date.toUTCString().replace(/UTC/, 'GMT'); | ||
while (millisecondsStr.length < 3) { | ||
millisecondsStr = '0' + millisecondsStr; | ||
millisecondsStr = "0" + millisecondsStr; | ||
} | ||
dateStr = dateStr.replace(' GMT', '.' + millisecondsStr + ' GMT'); | ||
dateStr = dateStr.replace(' GMT', ("." + millisecondsStr + " GMT")); | ||
} | ||
return output.jsKeyword('new').sp().text('Date(').append(_inspect6(dateStr).text(')')); | ||
return output | ||
.jsKeyword('new') | ||
.sp() | ||
.text('Date(') | ||
.append(inspect$1(dateStr).text(')')); | ||
} | ||
@@ -808,3 +968,2 @@ }); | ||
}, | ||
getKeys: Object.keys, | ||
@@ -814,20 +973,26 @@ equal: function equal(a, b) { | ||
}, | ||
inspect: function inspect(f, depth, output, _inspect7) { | ||
inspect: function inspect(f, depth, output, inspect$1) { | ||
// Don't break when a function has its own custom #toString: | ||
var source = Function.prototype.toString.call(f).replace(/\r\n?|\n\r?/g, '\n'); | ||
var source = Function.prototype.toString | ||
.call(f) | ||
.replace(/\r\n?|\n\r?/g, '\n'); | ||
var name = utils.getFunctionName(f) || ''; | ||
var preamble = void 0; | ||
var body = void 0; | ||
var bodyIndent = void 0; | ||
var matchSource = source.match(/^\s*((?:async )?\s*(?:\S+\s*=>|\([^)]*\)\s*=>|class|function\s?(?:\*\s*)?\w*\s*\([^)]*\)))([\s\S]*)$/); | ||
var preamble; | ||
var body; | ||
var bodyIndent; | ||
var matchSource = source.match( | ||
/^\s*((?:async )?\s*(?:\S+\s*=>|\([^)]*\)\s*=>|class|function\s?(?:\*\s*)?\w*\s*\([^)]*\)))([\s\S]*)$/ | ||
); | ||
if (matchSource) { | ||
// Normalize so there's always space after "function" and never after "*" for generator functions: | ||
preamble = matchSource[1].replace(/function(\S)/, 'function $1').replace(/\* /, '*'); | ||
preamble = matchSource[1] | ||
.replace(/function(\S)/, 'function $1') | ||
.replace(/\* /, '*'); | ||
if (preamble === 'function ()' && name) { | ||
// fn.bind() doesn't seem to include the name in the .toString() output: | ||
preamble = 'function ' + name + '()'; | ||
preamble = "function " + name + "()"; | ||
} | ||
body = matchSource[2]; | ||
var matchBodyAndIndent = body.match(/^(\s*\{)([\s\S]*?)([ ]*)\}\s*$/); | ||
var openingBrace = void 0; | ||
var openingBrace; | ||
var isWrappedInBraces = true; | ||
@@ -875,8 +1040,17 @@ var closingBrace = '}'; | ||
if (/\n/.test(body) && !/\\\n/.test(body)) { | ||
body = body.replace(new RegExp('^ {' + bodyIndent.length + '}', 'mg'), ''); | ||
body = body.replace(new RegExp(("^ {" + (bodyIndent.length) + "}"), 'mg'), ''); | ||
var indent = detectIndent(body); | ||
body = body.replace(new RegExp('^(?:' + indent.indent + ')*', 'mg'), function (_ref2) { | ||
var length = _ref2.length; | ||
return utils.leftPad('', (length / indent.amount + reindentBodyLevel) * output.indentationWidth, ' '); | ||
}); | ||
body = body.replace( | ||
new RegExp(("^(?:" + (indent.indent) + ")*"), 'mg'), | ||
function (ref) { | ||
var length = ref.length; | ||
return utils.leftPad( | ||
'', | ||
(length / indent.amount + reindentBodyLevel) * | ||
output.indentationWidth, | ||
' ' | ||
); | ||
} | ||
); | ||
} | ||
@@ -891,7 +1065,14 @@ if (!name || name === 'anonymous') { | ||
body = ''; | ||
} else if (/^\s*[^\r\n]{1,30}\s*$/.test(body) && body.indexOf('//') === -1 && isWrappedInBraces) { | ||
body = ' ' + body.trim() + ' '; | ||
} else if ( | ||
/^\s*[^\r\n]{1,30}\s*$/.test(body) && | ||
body.indexOf('//') === -1 && | ||
isWrappedInBraces | ||
) { | ||
body = " " + (body.trim()) + " "; | ||
closingBrace = '}'; | ||
} else { | ||
body = body.replace(/^((?:.*\n){3}( *).*\n)[\s\S]*?\n[\s\S]*?\n((?:.*\n){3})$/, '$1$2// ... lines removed ...\n$3'); | ||
body = body.replace( | ||
/^((?:.*\n){3}( *).*\n)[\s\S]*?\n[\s\S]*?\n((?:.*\n){3})$/, | ||
'$1$2// ... lines removed ...\n$3' | ||
); | ||
} | ||
@@ -905,3 +1086,3 @@ if (matchBodyAndIndent) { | ||
} else { | ||
preamble = 'function ' + name + '( /*...*/ ) '; | ||
preamble = "function " + name + "( /*...*/ ) "; | ||
body = '{ /*...*/ }'; | ||
@@ -925,5 +1106,5 @@ } | ||
}, | ||
inspect: function inspect(_ref3, depth, output, _inspect8) { | ||
var _expectations = _ref3._expectations, | ||
_OR = _ref3._OR; | ||
inspect: function inspect(ref, depth, output, inspect$1) { | ||
var _expectations = ref._expectations; | ||
var _OR = ref._OR; | ||
@@ -949,3 +1130,3 @@ output.text('expect.it('); | ||
} | ||
output.append(_inspect8(arg)); | ||
output.append(inspect$1(arg)); | ||
}); | ||
@@ -963,5 +1144,7 @@ orBranch = false; | ||
identify: function identify(obj) { | ||
return obj && this.baseType.identify(obj) && typeof obj.then === 'function'; | ||
return ( | ||
obj && this.baseType.identify(obj) && typeof obj.then === 'function' | ||
); | ||
}, | ||
inspect: function inspect(promise, depth, output, _inspect9) { | ||
inspect: function inspect(promise, depth, output, inspect$1) { | ||
output.jsFunctionName('Promise'); | ||
@@ -975,3 +1158,7 @@ if (promise.isPending && promise.isPending()) { | ||
if (typeof value !== 'undefined') { | ||
output.sp().text('=>').sp().append(_inspect9(value)); | ||
output | ||
.sp() | ||
.text('=>') | ||
.sp() | ||
.append(inspect$1(value)); | ||
} | ||
@@ -983,3 +1170,7 @@ } | ||
if (typeof reason !== 'undefined') { | ||
output.sp().text('=>').sp().append(_inspect9(promise.reason())); | ||
output | ||
.sp() | ||
.text('=>') | ||
.sp() | ||
.append(inspect$1(promise.reason())); | ||
} | ||
@@ -996,3 +1187,9 @@ } | ||
equal: function equal(a, b) { | ||
return a === b || a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline; | ||
return ( | ||
a === b || | ||
(a.source === b.source && | ||
a.global === b.global && | ||
a.ignoreCase === b.ignoreCase && | ||
a.multiline === b.multiline) | ||
); | ||
}, | ||
@@ -1002,3 +1199,3 @@ inspect: function inspect(regExp, depth, output) { | ||
}, | ||
diff: function diff(actual, expected, output, _diff5, inspect) { | ||
diff: function diff(actual, expected, output, diff$1, inspect) { | ||
output.inline = false; | ||
@@ -1019,3 +1216,3 @@ return output.stringDiff(String(actual), String(expected), { | ||
prefix: function prefix(output) { | ||
return output.code(this.name + '([', 'javascript'); | ||
return output.code(((this.name) + "(["), 'javascript'); | ||
}, | ||
@@ -1057,4 +1254,10 @@ suffix: function suffix(output) { | ||
var octet = obj[i + j]; | ||
hexChars += leftPad(octet.toString(16).toUpperCase(), this.digitWidth, '0') + ' '; | ||
asciiChars += String.fromCharCode(octet).replace(/\n/g, '␊').replace(/\r/g, '␍'); | ||
hexChars += (leftPad( | ||
octet.toString(16).toUpperCase(), | ||
this.digitWidth, | ||
'0' | ||
)) + " "; | ||
asciiChars += String.fromCharCode(octet) | ||
.replace(/\n/g, '␊') | ||
.replace(/\r/g, '␍'); | ||
} else if (this.digitWidth === 2) { | ||
@@ -1066,3 +1269,3 @@ hexChars += ' '; | ||
if (this.digitWidth === 2) { | ||
hexDump += hexChars + asciiChars + '\u2502'; | ||
hexDump += (hexChars + asciiChars) + "│"; | ||
} else { | ||
@@ -1082,6 +1285,10 @@ hexDump += hexChars.replace(/\s+$/, ''); | ||
var octet = obj[i]; | ||
codeStr += '0x' + leftPad(octet.toString(16).toUpperCase(), this.digitWidth, '0'); | ||
codeStr += "0x" + (leftPad( | ||
octet.toString(16).toUpperCase(), | ||
this.digitWidth, | ||
'0' | ||
)); | ||
} | ||
if (obj.length > this.hexDumpWidth) { | ||
codeStr += ' /* ' + (obj.length - this.hexDumpWidth) + ' more */ '; | ||
codeStr += " /* " + (obj.length - this.hexDumpWidth) + " more */ "; | ||
} | ||
@@ -1092,17 +1299,18 @@ output.code(codeStr, 'javascript'); | ||
}, | ||
diffLimit: 512, | ||
diff: function diff(actual, expected, output, _diff6, inspect) { | ||
diff: function diff(actual, expected, output, diff$1, inspect) { | ||
output.inline = false; | ||
if (Math.max(actual.length, expected.length) > this.diffLimit) { | ||
output.jsComment('Diff suppressed due to size > ' + this.diffLimit); | ||
output.jsComment(("Diff suppressed due to size > " + (this.diffLimit))); | ||
} else { | ||
output.stringDiff(this.hexDump(actual), this.hexDump(expected), { | ||
type: 'Chars', | ||
markUpSpecialCharacters: false | ||
}) | ||
// eslint-disable-next-line no-control-regex | ||
.replaceText(/[\x00-\x1f\x7f-\xff␊␍]/g, '.').replaceText(/[│ ]/g, function (styles, content) { | ||
this.text(content); | ||
}); | ||
output | ||
.stringDiff(this.hexDump(actual), this.hexDump(expected), { | ||
type: 'Chars', | ||
markUpSpecialCharacters: false | ||
}) | ||
// eslint-disable-next-line no-control-regex | ||
.replaceText(/[\x00-\x1f\x7f-\xff␊␍]/g, '.') | ||
.replaceText(/[│ ]/g, function(styles, content) { | ||
this.text(content); | ||
}); | ||
} | ||
@@ -1113,5 +1321,5 @@ return output; | ||
[8, 16, 32].forEach(function (numBits) { | ||
[8, 16, 32].forEach(function(numBits) { | ||
['Int', 'Uint'].forEach(function (intOrUint) { | ||
var constructorName = intOrUint + numBits + 'Array'; | ||
var constructorName = (intOrUint + numBits) + "Array"; | ||
var Constructor = global[constructorName]; | ||
@@ -1148,7 +1356,6 @@ if (typeof Constructor !== 'undefined') { | ||
}, | ||
diffLimit: 4096, | ||
diff: function diff(actual, expected, output, _diff7, inspect) { | ||
diff: function diff(actual, expected, output, diff$1, inspect) { | ||
if (Math.max(actual.length, expected.length) > this.diffLimit) { | ||
output.jsComment('Diff suppressed due to size > ' + this.diffLimit); | ||
output.jsComment(("Diff suppressed due to size > " + (this.diffLimit))); | ||
return output; | ||
@@ -1226,2 +1433,2 @@ } | ||
}); | ||
}; | ||
}; |
@@ -5,3 +5,10 @@ var utils = require('./utils'); | ||
var errorMethodBlacklist = ['message', 'line', 'sourceId', 'sourceURL', 'stack', 'stackArray'].reduce(function (result, prop) { | ||
var errorMethodBlacklist = [ | ||
'message', | ||
'line', | ||
'sourceId', | ||
'sourceURL', | ||
'stack', | ||
'stackArray' | ||
].reduce(function (result, prop) { | ||
result[prop] = true; | ||
@@ -12,3 +19,3 @@ return result; | ||
function UnexpectedError(expect, parent) { | ||
this.errorMode = expect && expect.errorMode || 'default'; | ||
this.errorMode = (expect && expect.errorMode) || 'default'; | ||
var base = Error.call(this, ''); | ||
@@ -42,4 +49,5 @@ | ||
var missingOutputMessage = 'You must either provide a format or a magicpen instance'; | ||
UnexpectedError.prototype.outputFromOptions = function (options) { | ||
var missingOutputMessage = | ||
'You must either provide a format or a magicpen instance'; | ||
UnexpectedError.prototype.outputFromOptions = function(options) { | ||
if (!options) { | ||
@@ -70,15 +78,17 @@ throw new Error(missingOutputMessage); | ||
UnexpectedError.prototype.isUnexpected = true; | ||
UnexpectedError.prototype.buildDiff = function (options) { | ||
UnexpectedError.prototype.buildDiff = function(options) { | ||
var output = this.outputFromOptions(options); | ||
var expect = this.expect; | ||
return this.createDiff && this.createDiff(output, function (actual, expected) { | ||
return expect.diff(actual, expected, output.clone()); | ||
}, function (v, depth) { | ||
return output.clone().appendInspected(v, (depth || defaultDepth) - 1); | ||
}, function (actual, expected) { | ||
return expect.equal(actual, expected); | ||
}); | ||
return ( | ||
this.createDiff && | ||
this.createDiff( | ||
output, | ||
function (actual, expected) { return expect.diff(actual, expected, output.clone()); }, | ||
function (v, depth) { return output.clone().appendInspected(v, (depth || defaultDepth) - 1); }, | ||
function (actual, expected) { return expect.equal(actual, expected); } | ||
) | ||
); | ||
}; | ||
UnexpectedError.prototype.getDefaultErrorMessage = function (options) { | ||
UnexpectedError.prototype.getDefaultErrorMessage = function(options) { | ||
var output = this.outputFromOptions(options); | ||
@@ -106,3 +116,3 @@ if (this.expect.testDescription) { | ||
UnexpectedError.prototype.getNestedErrorMessage = function (options) { | ||
UnexpectedError.prototype.getNestedErrorMessage = function(options) { | ||
var output = this.outputFromOptions(options); | ||
@@ -126,9 +136,17 @@ if (this.expect.testDescription) { | ||
output.nl().indentLines().i().block(parent.getErrorMessage(utils.extend({}, options || {}, { | ||
compact: this.expect.subject === parent.expect.subject | ||
}))); | ||
output | ||
.nl() | ||
.indentLines() | ||
.i() | ||
.block( | ||
parent.getErrorMessage( | ||
utils.extend({}, options || {}, { | ||
compact: this.expect.subject === parent.expect.subject | ||
}) | ||
) | ||
); | ||
return output; | ||
}; | ||
UnexpectedError.prototype.getDefaultOrNestedMessage = function (options) { | ||
UnexpectedError.prototype.getDefaultOrNestedMessage = function(options) { | ||
if (this.hasDiff()) { | ||
@@ -141,7 +159,7 @@ return this.getDefaultErrorMessage(options); | ||
UnexpectedError.prototype.hasDiff = function () { | ||
UnexpectedError.prototype.hasDiff = function() { | ||
return !!this.getDiffMethod(); | ||
}; | ||
UnexpectedError.prototype.getDiffMethod = function () { | ||
UnexpectedError.prototype.getDiffMethod = function() { | ||
var errorWithDiff = this; | ||
@@ -152,6 +170,6 @@ while (!errorWithDiff.createDiff && errorWithDiff.parent) { | ||
return errorWithDiff && errorWithDiff.createDiff || null; | ||
return (errorWithDiff && errorWithDiff.createDiff) || null; | ||
}; | ||
UnexpectedError.prototype.getDiff = function (options) { | ||
UnexpectedError.prototype.getDiff = function(options) { | ||
var errorWithDiff = this; | ||
@@ -165,3 +183,3 @@ while (!errorWithDiff.createDiff && errorWithDiff.parent) { | ||
UnexpectedError.prototype.getDiffMessage = function (options) { | ||
UnexpectedError.prototype.getDiffMessage = function(options) { | ||
var output = this.outputFromOptions(options); | ||
@@ -179,3 +197,3 @@ var comparison = this.getDiff(options); | ||
UnexpectedError.prototype.getErrorMode = function () { | ||
UnexpectedError.prototype.getErrorMode = function() { | ||
if (!this.parent) { | ||
@@ -194,7 +212,10 @@ switch (this.errorMode) { | ||
UnexpectedError.prototype.getErrorMessage = function (options) { | ||
UnexpectedError.prototype.getErrorMessage = function(options) { | ||
// Search for any parent error that has an error mode of 'bubbleThrough' through on the | ||
// error these should be bubbled to the top | ||
var errorWithBubbleThrough = this.parent; | ||
while (errorWithBubbleThrough && errorWithBubbleThrough.getErrorMode() !== 'bubbleThrough') { | ||
while ( | ||
errorWithBubbleThrough && | ||
errorWithBubbleThrough.getErrorMode() !== 'bubbleThrough' | ||
) { | ||
errorWithBubbleThrough = errorWithBubbleThrough.parent; | ||
@@ -221,3 +242,3 @@ } | ||
default: | ||
throw new Error('Unknown error mode: \'' + errorMode + '\''); | ||
throw new Error(("Unknown error mode: '" + errorMode + "'")); | ||
} | ||
@@ -236,3 +257,3 @@ }; | ||
UnexpectedError.prototype.serializeMessage = function (outputFormat) { | ||
UnexpectedError.prototype.serializeMessage = function(outputFormat) { | ||
if (!this._hasSerializedErrorMessage) { | ||
@@ -246,7 +267,11 @@ var htmlFormat = outputFormat === 'html'; | ||
this.message = '\n' + this.getErrorMessage({ | ||
this.message = "\n" + (this.getErrorMessage({ | ||
format: htmlFormat ? 'text' : outputFormat | ||
}).toString() + '\n'; | ||
}).toString()) + "\n"; | ||
if (this.originalError && this.originalError instanceof Error && typeof this.originalError.stack === 'string') { | ||
if ( | ||
this.originalError && | ||
this.originalError instanceof Error && | ||
typeof this.originalError.stack === 'string' | ||
) { | ||
// The stack of the original error looks like this: | ||
@@ -256,8 +281,14 @@ // <constructor name>: <error message>\n<actual stack trace> | ||
// to the error message of this error: | ||
var index = this.originalError.stack.indexOf(this.originalError.message); | ||
var index = this.originalError.stack.indexOf( | ||
this.originalError.message | ||
); | ||
if (index === -1) { | ||
// Phantom.js doesn't include the error message in the stack property | ||
this.stack = this.message + '\n' + this.originalError.stack; | ||
this.stack = (this.message) + "\n" + (this.originalError.stack); | ||
} else { | ||
this.stack = this.message + this.originalError.stack.substr(index + this.originalError.message.length); | ||
this.stack = | ||
this.message + | ||
this.originalError.stack.substr( | ||
index + this.originalError.message.length | ||
); | ||
} | ||
@@ -276,5 +307,9 @@ } else if (/^(Unexpected)?Error:?\n/.test(this.stack)) { | ||
var newStack = lines.filter(function (line, i) { | ||
return i < stackStart || !/node_modules[/\\]unexpected(?:-[^/\\]+)?[/\\]/.test(line) && !/executeExpect.*node_modules[/\\]unexpected[/\\]/.test(lines[i + 1]); | ||
}); | ||
var newStack = lines.filter( | ||
function (line, i) { return i < stackStart || | ||
(!/node_modules[/\\]unexpected(?:-[^/\\]+)?[/\\]/.test(line) && | ||
!/executeExpect.*node_modules[/\\]unexpected[/\\]/.test( | ||
lines[i + 1] | ||
)); } | ||
); | ||
@@ -285,5 +320,9 @@ if (newStack.length !== lines.length) { | ||
if (outputFormat === 'html') { | ||
newStack.push(indentation + 'set the query parameter full-trace=true to see the full stack trace'); | ||
newStack.push( | ||
(indentation + "set the query parameter full-trace=true to see the full stack trace") | ||
); | ||
} else { | ||
newStack.push(indentation + 'set UNEXPECTED_FULL_TRACE=true to see the full stack trace'); | ||
newStack.push( | ||
(indentation + "set UNEXPECTED_FULL_TRACE=true to see the full stack trace") | ||
); | ||
} | ||
@@ -299,3 +338,3 @@ } | ||
UnexpectedError.prototype.clone = function () { | ||
UnexpectedError.prototype.clone = function() { | ||
var that = this; | ||
@@ -311,3 +350,3 @@ var newError = new UnexpectedError(this.expect); | ||
UnexpectedError.prototype.getLabel = function () { | ||
UnexpectedError.prototype.getLabel = function() { | ||
var currentError = this; | ||
@@ -317,6 +356,6 @@ while (currentError && !currentError.label) { | ||
} | ||
return currentError && currentError.label || null; | ||
return (currentError && currentError.label) || null; | ||
}; | ||
UnexpectedError.prototype.getParents = function () { | ||
UnexpectedError.prototype.getParents = function() { | ||
var result = []; | ||
@@ -331,3 +370,3 @@ var parent = this.parent; | ||
UnexpectedError.prototype.getAllErrors = function () { | ||
UnexpectedError.prototype.getAllErrors = function() { | ||
var result = this.getParents(); | ||
@@ -347,2 +386,2 @@ result.unshift(this); | ||
module.exports = UnexpectedError; | ||
module.exports = UnexpectedError; |
@@ -5,9 +5,15 @@ /* global window */ | ||
if (typeof window !== 'undefined' && typeof window.location !== 'undefined') { | ||
useFullStackTrace = !!window.location.search.match(/[?&]full-trace=true(?:$|&)/); | ||
useFullStackTrace = !!window.location.search.match( | ||
/[?&]full-trace=true(?:$|&)/ | ||
); | ||
} | ||
if (typeof process !== 'undefined' && process.env && process.env.UNEXPECTED_FULL_TRACE) { | ||
if ( | ||
typeof process !== 'undefined' && | ||
process.env && | ||
process.env.UNEXPECTED_FULL_TRACE | ||
) { | ||
Promise.longStackTraces(); | ||
useFullStackTrace = true; | ||
} | ||
module.exports = useFullStackTrace; | ||
module.exports = useFullStackTrace; |
@@ -1,30 +0,29 @@ | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint-disable no-proto */ | ||
var canSetPrototype = Object.setPrototypeOf || { __proto__: [] } instanceof Array; | ||
var canSetPrototype = | ||
Object.setPrototypeOf || { __proto__: [] } instanceof Array; | ||
var greedyIntervalPacker = require('greedy-interval-packer'); | ||
var setPrototypeOf = Object.setPrototypeOf || function setPrototypeOf(obj, proto) { | ||
obj.__proto__ = proto; | ||
return obj; | ||
}; | ||
var setPrototypeOf = | ||
Object.setPrototypeOf || | ||
function setPrototypeOf(obj, proto) { | ||
obj.__proto__ = proto; | ||
return obj; | ||
}; | ||
/* eslint-enable no-proto */ | ||
var utils = module.exports = { | ||
objectIs: Object.is || function (a, b) { | ||
// Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
if (a === 0 && b === 0) { | ||
return 1 / a === 1 / b; | ||
} | ||
// eslint-disable-next-line no-self-compare | ||
if (a !== a) { | ||
var utils = (module.exports = { | ||
objectIs: | ||
Object.is || | ||
(function (a, b) { | ||
// Polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
if (a === 0 && b === 0) { | ||
return 1 / a === 1 / b; | ||
} | ||
// eslint-disable-next-line no-self-compare | ||
return b !== b; | ||
} | ||
return a === b; | ||
}, | ||
if (a !== a) { | ||
// eslint-disable-next-line no-self-compare | ||
return b !== b; | ||
} | ||
return a === b; | ||
}), | ||
@@ -40,8 +39,8 @@ checkObjectEqualityUsingType: function checkObjectEqualityUsingType(a, b, type, isEqual) { | ||
var actualKeys = type.getKeys(a).filter(function (key) { | ||
return typeof type.valueForKey(a, key) !== 'undefined'; | ||
}); | ||
var expectedKeys = type.getKeys(b).filter(function (key) { | ||
return typeof type.valueForKey(b, key) !== 'undefined'; | ||
}); | ||
var actualKeys = type | ||
.getKeys(a) | ||
.filter(function (key) { return typeof type.valueForKey(a, key) !== 'undefined'; }); | ||
var expectedKeys = type | ||
.getKeys(b) | ||
.filter(function (key) { return typeof type.valueForKey(b, key) !== 'undefined'; }); | ||
@@ -73,2 +72,3 @@ // having the same number of owned properties (keys incorporates hasOwnProperty) | ||
}, | ||
duplicateArrayLikeUsingType: function duplicateArrayLikeUsingType(obj, type) { | ||
@@ -83,3 +83,3 @@ var keys = type.getKeys(obj); | ||
var key = keys[i]; | ||
if ((typeof key === 'undefined' ? 'undefined' : (0, _typeof3.default)(key)) === 'symbol' || !utils.numericalRegExp.test(key)) { | ||
if (typeof key === 'symbol' || !utils.numericalRegExp.test(key)) { | ||
nonNumericalKeyLength += 1; | ||
@@ -96,3 +96,3 @@ } else { | ||
keys.forEach(function (key, index) { | ||
keys.forEach(function(key, index) { | ||
var isNonNumericKey = index >= numericalKeyLength; | ||
@@ -109,19 +109,28 @@ if (isNonNumericKey && !type.hasKey(obj, key)) { | ||
}, | ||
isArray: function isArray(ar) { | ||
return Object.prototype.toString.call(ar) === '[object Array]'; | ||
}, | ||
isPromise: function isPromise(obj) { | ||
return obj && typeof obj.then === 'function'; | ||
}, | ||
isRegExp: function isRegExp(re) { | ||
return Object.prototype.toString.call(re) === '[object RegExp]'; | ||
}, | ||
isError: function isError(err) { | ||
return (typeof err === 'undefined' ? 'undefined' : (0, _typeof3.default)(err)) === 'object' && (Object.prototype.toString.call(err) === '[object Error]' || err instanceof Error); | ||
return ( | ||
typeof err === 'object' && | ||
(Object.prototype.toString.call(err) === '[object Error]' || | ||
err instanceof Error) | ||
); | ||
}, | ||
extend: function extend(target) { | ||
var _arguments = arguments; | ||
var arguments$1 = arguments; | ||
var _loop = function _loop(i) { | ||
var source = _arguments[i]; | ||
var loop = function ( i ) { | ||
var source = arguments$1[i]; | ||
if (source) { | ||
@@ -134,7 +143,6 @@ Object.keys(source).forEach(function (key) { | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
_loop(i); | ||
} | ||
for (var i = 1; i < arguments.length; i += 1) loop( i ); | ||
return target; | ||
}, | ||
findFirst: function findFirst(arr, predicate) { | ||
@@ -148,5 +156,6 @@ for (var i = 0; i < arr.length; i += 1) { | ||
}, | ||
leftPad: function leftPad(str, width) { | ||
var ch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' '; | ||
leftPad: function leftPad(str, width, ch) { | ||
if ( ch === void 0 ) ch = ' '; | ||
while (str.length < width) { | ||
@@ -157,5 +166,7 @@ str = ch + str; | ||
}, | ||
escapeRegExpMetaChars: function escapeRegExpMetaChars(str) { | ||
return str.replace(/[[\]{}()*+?.\\^$|]/g, '\\$&'); | ||
}, | ||
escapeChar: function escapeChar(ch) { | ||
@@ -170,8 +181,9 @@ if (ch === '\t') { | ||
if (charCode < 256) { | ||
return '\\x' + utils.leftPad(hexChars, 2, '0'); | ||
return ("\\x" + (utils.leftPad(hexChars, 2, '0'))); | ||
} else { | ||
return '\\u' + utils.leftPad(hexChars, 4, '0'); | ||
return ("\\u" + (utils.leftPad(hexChars, 4, '0'))); | ||
} | ||
} | ||
}, | ||
getFunctionName: function getFunctionName(f) { | ||
@@ -181,3 +193,5 @@ if (typeof f.name === 'string') { | ||
} | ||
var matchFunctionName = Function.prototype.toString.call(f).match(/function ([^(]+)/); | ||
var matchFunctionName = Function.prototype.toString | ||
.call(f) | ||
.match(/function ([^(]+)/); | ||
if (matchFunctionName) { | ||
@@ -195,7 +209,15 @@ return matchFunctionName[1]; | ||
}, | ||
wrapConstructorNameAroundOutput: function wrapConstructorNameAroundOutput(output, obj) { | ||
var constructor = obj.constructor; | ||
var constructorName = constructor && constructor !== Object && utils.getFunctionName(constructor); | ||
var constructorName = | ||
constructor && | ||
constructor !== Object && | ||
utils.getFunctionName(constructor); | ||
if (constructorName && constructorName !== 'Object') { | ||
return output.clone().text(constructorName + '(').append(output).text(')'); | ||
return output | ||
.clone() | ||
.text((constructorName + "(")) | ||
.append(output) | ||
.text(')'); | ||
} else { | ||
@@ -206,17 +228,21 @@ return output; | ||
setPrototypeOfOrExtend: canSetPrototype | ||
? setPrototypeOf | ||
: function extend(target, source) { | ||
for (var prop in source) { | ||
if (source.hasOwnProperty(prop)) { | ||
target[prop] = source[prop]; | ||
} | ||
} | ||
return target; | ||
}, | ||
setPrototypeOfOrExtend: canSetPrototype ? setPrototypeOf : function extend(target, source) { | ||
for (var prop in source) { | ||
if (source.hasOwnProperty(prop)) { | ||
target[prop] = source[prop]; | ||
} | ||
} | ||
return target; | ||
}, | ||
uniqueStringsAndSymbols: function uniqueStringsAndSymbols() { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
uniqueStringsAndSymbols: function uniqueStringsAndSymbols() { | ||
// [filterFn], item1, item2... | ||
var filterFn = void 0; | ||
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'function') { | ||
filterFn = arguments.length <= 0 ? undefined : arguments[0]; | ||
var filterFn; | ||
if (typeof args[0] === 'function') { | ||
filterFn = args[0]; | ||
} | ||
@@ -229,3 +255,6 @@ var index = {}; | ||
item.forEach(visit); | ||
} else if (!Object.prototype.hasOwnProperty.call(index, item) && (!filterFn || filterFn(item))) { | ||
} else if ( | ||
!Object.prototype.hasOwnProperty.call(index, item) && | ||
(!filterFn || filterFn(item)) | ||
) { | ||
index[item] = true; | ||
@@ -236,24 +265,27 @@ uniqueStringsAndSymbols.push(item); | ||
for (var i = filterFn ? 1 : 0; i < arguments.length; i += 1) { | ||
visit(arguments.length <= i ? undefined : arguments[i]); | ||
for (var i = filterFn ? 1 : 0; i < args.length; i += 1) { | ||
visit(args[i]); | ||
} | ||
return uniqueStringsAndSymbols; | ||
}, | ||
uniqueNonNumericalStringsAndSymbols: function uniqueNonNumericalStringsAndSymbols() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
// ... | ||
return utils.uniqueStringsAndSymbols(function (stringOrSymbol) { | ||
return (typeof stringOrSymbol === 'undefined' ? 'undefined' : (0, _typeof3.default)(stringOrSymbol)) === 'symbol' || !utils.numericalRegExp.test(stringOrSymbol); | ||
}, Array.prototype.slice.call(args)); | ||
return utils.uniqueStringsAndSymbols( | ||
function (stringOrSymbol) { return typeof stringOrSymbol === 'symbol' || | ||
!utils.numericalRegExp.test(stringOrSymbol); }, | ||
Array.prototype.slice.call(args) | ||
); | ||
}, | ||
forwardFlags: function forwardFlags(testDescriptionString, flags) { | ||
return testDescriptionString.replace(/\[(!?)([^\]]+)\] ?/g, function (match, negate, flag) { | ||
return Boolean(flags[flag]) !== Boolean(negate) ? flag + ' ' : ''; | ||
}).trim(); | ||
return testDescriptionString | ||
.replace(/\[(!?)([^\]]+)\] ?/g, function (match, negate, flag) { return Boolean(flags[flag]) !== Boolean(negate) ? (flag + " ") : ''; } | ||
) | ||
.trim(); | ||
}, | ||
numericalRegExp: /^(?:0|[1-9][0-9]*)$/, | ||
@@ -266,6 +298,10 @@ | ||
diffItem.changeIndex = index; | ||
(moveSourceAndTargetByActualIndex[diffItem.actualIndex] = moveSourceAndTargetByActualIndex[diffItem.actualIndex] || {}).source = diffItem; | ||
(moveSourceAndTargetByActualIndex[diffItem.actualIndex] = | ||
moveSourceAndTargetByActualIndex[diffItem.actualIndex] || | ||
{}).source = diffItem; | ||
} else if (diffItem.type === 'moveTarget') { | ||
diffItem.changeIndex = index; | ||
(moveSourceAndTargetByActualIndex[diffItem.actualIndex] = moveSourceAndTargetByActualIndex[diffItem.actualIndex] || {}).target = diffItem; | ||
(moveSourceAndTargetByActualIndex[diffItem.actualIndex] = | ||
moveSourceAndTargetByActualIndex[diffItem.actualIndex] || | ||
{}).target = diffItem; | ||
} | ||
@@ -276,16 +312,38 @@ }); | ||
var arrowSpecs = []; | ||
moveIndices.sort(function (a, b // Order by distance between change indices descending | ||
) { | ||
return Math.abs(moveSourceAndTargetByActualIndex[b].source.changeIndex - moveSourceAndTargetByActualIndex[b].target.changeIndex) - Math.abs(moveSourceAndTargetByActualIndex[a].source.changeIndex - moveSourceAndTargetByActualIndex[a].target.changeIndex); | ||
}).forEach(function (actualIndex, i, keys) { | ||
var moveSourceAndMoveTarget = moveSourceAndTargetByActualIndex[actualIndex]; | ||
var firstChangeIndex = Math.min(moveSourceAndMoveTarget.source.changeIndex, moveSourceAndMoveTarget.target.changeIndex); | ||
var lastChangeIndex = Math.max(moveSourceAndMoveTarget.source.changeIndex, moveSourceAndMoveTarget.target.changeIndex); | ||
moveIndices | ||
.sort( | ||
function ( | ||
a, | ||
b // Order by distance between change indices descending | ||
) { return Math.abs( | ||
moveSourceAndTargetByActualIndex[b].source.changeIndex - | ||
moveSourceAndTargetByActualIndex[b].target.changeIndex | ||
) - | ||
Math.abs( | ||
moveSourceAndTargetByActualIndex[a].source.changeIndex - | ||
moveSourceAndTargetByActualIndex[a].target.changeIndex | ||
); } | ||
) | ||
.forEach(function (actualIndex, i, keys) { | ||
var moveSourceAndMoveTarget = | ||
moveSourceAndTargetByActualIndex[actualIndex]; | ||
var firstChangeIndex = Math.min( | ||
moveSourceAndMoveTarget.source.changeIndex, | ||
moveSourceAndMoveTarget.target.changeIndex | ||
); | ||
var lastChangeIndex = Math.max( | ||
moveSourceAndMoveTarget.source.changeIndex, | ||
moveSourceAndMoveTarget.target.changeIndex | ||
); | ||
arrowSpecs.push({ | ||
start: firstChangeIndex, | ||
end: lastChangeIndex, | ||
direction: moveSourceAndMoveTarget.source.changeIndex < moveSourceAndMoveTarget.target.changeIndex ? 'down' : 'up' | ||
arrowSpecs.push({ | ||
start: firstChangeIndex, | ||
end: lastChangeIndex, | ||
direction: | ||
moveSourceAndMoveTarget.source.changeIndex < | ||
moveSourceAndMoveTarget.target.changeIndex | ||
? 'down' | ||
: 'up' | ||
}); | ||
}); | ||
}); | ||
@@ -295,6 +353,6 @@ var packing = greedyIntervalPacker(arrowSpecs); | ||
// The arrow packing takes up too many lanes. Turn the moveSource/moveTarget items into inserts and removes | ||
packing.shift().forEach(function (_ref) { | ||
var direction = _ref.direction, | ||
start = _ref.start, | ||
end = _ref.end; | ||
packing.shift().forEach(function (ref) { | ||
var direction = ref.direction; | ||
var start = ref.start; | ||
var end = ref.end; | ||
@@ -308,2 +366,3 @@ changes[direction === 'up' ? start : end].type = 'insert'; | ||
}, | ||
truncateSubjectStringForBegin: function truncateSubjectStringForBegin(subject, value) { | ||
@@ -321,2 +380,3 @@ var contextLength = value.length + 25; | ||
}, | ||
truncateSubjectStringForEnd: function truncateSubjectStringForEnd(subject, value) { | ||
@@ -334,2 +394,2 @@ var contextLength = subject.length - value.length - 25; | ||
} | ||
}; | ||
}); |
@@ -20,3 +20,3 @@ var Promise = require('unexpected-bluebird'); | ||
Promise.prototype._notifyUnhandledRejection = function () { | ||
Promise.prototype._notifyUnhandledRejection = function() { | ||
var that = this; | ||
@@ -35,2 +35,2 @@ scheduler(function () { | ||
module.exports = workQueue; | ||
module.exports = workQueue; |
@@ -6,8 +6,6 @@ var makePromise = require('./makePromise'); | ||
// wrap any non-Unexpected promise | ||
return makePromise(function () { | ||
return promise; | ||
}); | ||
return makePromise(function () { return promise; }); | ||
} else { | ||
return promise; | ||
} | ||
}; | ||
}; |
{ | ||
"name": "unexpected", | ||
"version": "11.1.2", | ||
"version": "11.2.0", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -27,3 +27,2 @@ "keywords": [ | ||
"array-changes-async": "3.0.1", | ||
"babel-runtime": "6.26.0", | ||
"detect-indent": "3.0.1", | ||
@@ -37,5 +36,3 @@ "diff": "4.0.1", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-es2015-without-strict": "^0.0.4", | ||
"buble": "^0.19.7", | ||
"coveralls": "^3.0.0", | ||
@@ -56,3 +53,3 @@ "eslint": "^5.11.1", | ||
"jasmine-core": "^3.1.0", | ||
"jest": "^23.0.0", | ||
"jest": "^24.4.0", | ||
"karma": "4.0.1", | ||
@@ -59,0 +56,0 @@ "karma-browserstack-launcher": "1.4.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
8
38
6
1877130
53
15515
- Removedbabel-runtime@6.26.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)