diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 9c86dcda..fa9938e6 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -4926,11 +4926,12 @@ getJasmineRequireObj().toBeResolvedTo = function(j$) { getJasmineRequireObj().DiffBuilder = function(j$) { return function DiffBuilder(config) { - var prettyPrinter = (config || {}).prettyPrinter || j$.makePrettyPrinter(), - mismatches = new j$.MismatchTree(), - path = new j$.ObjectPath(), - actualRoot = undefined, - expectedRoot = undefined; + const prettyPrinter = + (config || {}).prettyPrinter || j$.makePrettyPrinter(); + const mismatches = new j$.MismatchTree(); + let path = new j$.ObjectPath(); + let actualRoot = undefined; + let expectedRoot = undefined; return { setRoots: function(actual, expected) { @@ -4943,29 +4944,24 @@ getJasmineRequireObj().DiffBuilder = function(j$) { }, getMessage: function() { - var messages = []; + const messages = []; mismatches.traverse(function(path, isLeaf, formatter) { - var actualCustom, - expectedCustom, - useCustom, - derefResult = dereferencePath( - path, - actualRoot, - expectedRoot, - prettyPrinter - ), - actual = derefResult.actual, - expected = derefResult.expected; + const { actual, expected } = dereferencePath( + path, + actualRoot, + expectedRoot, + prettyPrinter + ); if (formatter) { messages.push(formatter(actual, expected, path, prettyPrinter)); return true; } - actualCustom = prettyPrinter.customFormat_(actual); - expectedCustom = prettyPrinter.customFormat_(expected); - useCustom = !( + const actualCustom = prettyPrinter.customFormat_(actual); + const expectedCustom = prettyPrinter.customFormat_(expected); + const useCustom = !( j$.util.isUndefined(actualCustom) && j$.util.isUndefined(expectedCustom) ); @@ -4990,7 +4986,7 @@ getJasmineRequireObj().DiffBuilder = function(j$) { }, withPath: function(pathComponent, block) { - var oldPath = path; + const oldPath = path; path = path.add(pathComponent); block(); path = oldPath; @@ -5024,18 +5020,17 @@ getJasmineRequireObj().DiffBuilder = function(j$) { j$.isAsymmetricEqualityTester_(expected) && j$.isFunction_(expected.valuesForDiff_) ) { - var asymmetricResult = expected.valuesForDiff_(actual, pp); + const asymmetricResult = expected.valuesForDiff_(actual, pp); expected = asymmetricResult.self; actual = asymmetricResult.other; } } - var i; handleAsymmetricExpected(); - for (i = 0; i < objectPath.components.length; i++) { - actual = actual[objectPath.components[i]]; - expected = expected[objectPath.components[i]]; + for (const pc of objectPath.components) { + actual = actual[pc]; + expected = expected[pc]; handleAsymmetricExpected(); } @@ -5748,15 +5743,13 @@ getJasmineRequireObj().MismatchTree = function(j$) { } MismatchTree.prototype.add = function(path, formatter) { - var key, child; - if (path.depth() === 0) { this.formatter = formatter; this.isMismatch = true; } else { - key = path.components[0]; + const key = path.components[0]; path = path.shift(); - child = this.child(key); + let child = this.child(key); if (!child) { child = new MismatchTree(this.path.add(key)); @@ -5768,27 +5761,22 @@ getJasmineRequireObj().MismatchTree = function(j$) { }; MismatchTree.prototype.traverse = function(visit) { - var i, - hasChildren = this.children.length > 0; + const hasChildren = this.children.length > 0; if (this.isMismatch || hasChildren) { if (visit(this.path, !hasChildren, this.formatter)) { - for (i = 0; i < this.children.length; i++) { - this.children[i].traverse(visit); + for (const child of this.children) { + child.traverse(visit); } } } }; MismatchTree.prototype.child = function(key) { - var i, pathEls; - - for (i = 0; i < this.children.length; i++) { - pathEls = this.children[i].path.components; - if (pathEls[pathEls.length - 1] === key) { - return this.children[i]; - } - } + return this.children.find(child => { + const pathEls = child.path.components; + return pathEls[pathEls.length - 1] === key; + }); }; return MismatchTree; @@ -5835,7 +5823,7 @@ getJasmineRequireObj().ObjectPath = function(j$) { ObjectPath.prototype.toString = function() { if (this.components.length) { - return '$' + map(this.components, formatPropertyAccess).join(''); + return '$' + this.components.map(formatPropertyAccess).join(''); } else { return ''; } @@ -5865,14 +5853,6 @@ getJasmineRequireObj().ObjectPath = function(j$) { return "['" + prop + "']"; } - function map(array, fn) { - var results = []; - for (var i = 0; i < array.length; i++) { - results.push(fn(array[i])); - } - return results; - } - function isValidIdentifier(string) { return /^[A-Za-z\$_][A-Za-z0-9\$_]*$/.test(string); } @@ -7568,7 +7548,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { SinglePrettyPrintRun.prototype.format = function(value) { this.ppNestLevel_++; try { - var customFormatResult = this.applyCustomFormatters_(value); + const customFormatResult = this.applyCustomFormatters_(value); if (customFormatResult) { this.emitScalar(customFormatResult); @@ -7648,10 +7628,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) { - var objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj)); - var length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + const objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj)); + const length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); - for (var i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { fn(objKeys[i]); } @@ -7671,9 +7651,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { this.append('Array'); return; } - var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + + const length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); this.append('[ '); - for (var i = 0; i < length; i++) { + + for (let i = 0; i < length; i++) { if (i > 0) { this.append(', '); } @@ -7683,19 +7665,18 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { this.append(', ...'); } - var self = this; - var first = array.length === 0; - var truncated = this.iterateObject(array, function(property) { + let first = array.length === 0; + const wasTruncated = this.iterateObject(array, property => { if (first) { first = false; } else { - self.append(', '); + this.append(', '); } - self.formatProperty(array, property); + this.formatProperty(array, property); }); - if (truncated) { + if (wasTruncated) { this.append(', ...'); } @@ -7708,8 +7689,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return; } this.append('Set( '); - var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); - var i = 0; + const size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + let i = 0; set.forEach(function(value, key) { if (i >= size) { return; @@ -7733,8 +7714,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return; } this.append('Map( '); - var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); - var i = 0; + const size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + let i = 0; map.forEach(function(value, key) { if (i >= size) { return; @@ -7753,10 +7734,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.emitObject = function(obj) { - var ctor = obj.constructor, - constructorName; - - constructorName = + const ctor = obj.constructor; + const constructorName = typeof ctor === 'function' && obj instanceof ctor ? j$.fnNameFor(obj.constructor) : 'null'; @@ -7767,21 +7746,20 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return; } - var self = this; this.append('({ '); - var first = true; + let first = true; - var truncated = this.iterateObject(obj, function(property) { + const wasTruncated = this.iterateObject(obj, property => { if (first) { first = false; } else { - self.append(', '); + this.append(', '); } - self.formatProperty(obj, property); + this.formatProperty(obj, property); }); - if (truncated) { + if (wasTruncated) { this.append(', ...'); } @@ -7789,13 +7767,13 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) { - var constructorName = j$.fnNameFor(arr.constructor), - limitedArray = Array.prototype.slice.call( - arr, - 0, - j$.MAX_PRETTY_PRINT_ARRAY_LENGTH - ), - itemsString = Array.prototype.join.call(limitedArray, ', '); + const constructorName = j$.fnNameFor(arr.constructor); + const limitedArray = Array.prototype.slice.call( + arr, + 0, + j$.MAX_PRETTY_PRINT_ARRAY_LENGTH + ); + let itemsString = Array.prototype.join.call(limitedArray, ', '); if (limitedArray.length !== arr.length) { itemsString += ', ...'; @@ -7805,15 +7783,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.emitDomElement = function(el) { - var tagName = el.tagName.toLowerCase(), - attrs = el.attributes, - i, - len = attrs.length, - out = '<' + tagName, - attr; + const tagName = el.tagName.toLowerCase(); + let out = '<' + tagName; - for (i = 0; i < len; i++) { - attr = attrs[i]; + for (const attr of el.attributes) { out += ' ' + attr.name; if (attr.value !== '') { @@ -7848,7 +7821,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { value = Object.prototype.toString.call(value); } - var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length); + const result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length); this.length += result.value.length; this.stringParts.push(result.value); @@ -7876,10 +7849,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { MaxCharsReachedError.prototype = new Error(); function customFormat(value, customObjectFormatters) { - var i, result; - - for (i = 0; i < customObjectFormatters.length; i++) { - result = customObjectFormatters[i](value); + for (const formatter of customObjectFormatters) { + const result = formatter(value); if (result !== undefined) { return result; @@ -7890,8 +7861,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return function(customObjectFormatters) { customObjectFormatters = customObjectFormatters || []; - var pp = function(value) { - var prettyPrinter = new SinglePrettyPrintRun(customObjectFormatters, pp); + const pp = function(value) { + const prettyPrinter = new SinglePrettyPrintRun( + customObjectFormatters, + pp + ); prettyPrinter.format(value); return prettyPrinter.stringParts.join(''); }; diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js index 08f3c925..8e1dae36 100644 --- a/src/core/PrettyPrinter.js +++ b/src/core/PrettyPrinter.js @@ -26,7 +26,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { SinglePrettyPrintRun.prototype.format = function(value) { this.ppNestLevel_++; try { - var customFormatResult = this.applyCustomFormatters_(value); + const customFormatResult = this.applyCustomFormatters_(value); if (customFormatResult) { this.emitScalar(customFormatResult); @@ -106,10 +106,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.iterateObject = function(obj, fn) { - var objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj)); - var length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + const objKeys = j$.MatchersUtil.keys(obj, j$.isArray_(obj)); + const length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); - for (var i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { fn(objKeys[i]); } @@ -129,9 +129,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { this.append('Array'); return; } - var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + + const length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); this.append('[ '); - for (var i = 0; i < length; i++) { + + for (let i = 0; i < length; i++) { if (i > 0) { this.append(', '); } @@ -141,19 +143,18 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { this.append(', ...'); } - var self = this; - var first = array.length === 0; - var truncated = this.iterateObject(array, function(property) { + let first = array.length === 0; + const wasTruncated = this.iterateObject(array, property => { if (first) { first = false; } else { - self.append(', '); + this.append(', '); } - self.formatProperty(array, property); + this.formatProperty(array, property); }); - if (truncated) { + if (wasTruncated) { this.append(', ...'); } @@ -166,8 +167,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return; } this.append('Set( '); - var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); - var i = 0; + const size = Math.min(set.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + let i = 0; set.forEach(function(value, key) { if (i >= size) { return; @@ -191,8 +192,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return; } this.append('Map( '); - var size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); - var i = 0; + const size = Math.min(map.size, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); + let i = 0; map.forEach(function(value, key) { if (i >= size) { return; @@ -211,10 +212,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.emitObject = function(obj) { - var ctor = obj.constructor, - constructorName; - - constructorName = + const ctor = obj.constructor; + const constructorName = typeof ctor === 'function' && obj instanceof ctor ? j$.fnNameFor(obj.constructor) : 'null'; @@ -225,21 +224,20 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return; } - var self = this; this.append('({ '); - var first = true; + let first = true; - var truncated = this.iterateObject(obj, function(property) { + const wasTruncated = this.iterateObject(obj, property => { if (first) { first = false; } else { - self.append(', '); + this.append(', '); } - self.formatProperty(obj, property); + this.formatProperty(obj, property); }); - if (truncated) { + if (wasTruncated) { this.append(', ...'); } @@ -247,13 +245,13 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.emitTypedArray = function(arr) { - var constructorName = j$.fnNameFor(arr.constructor), - limitedArray = Array.prototype.slice.call( - arr, - 0, - j$.MAX_PRETTY_PRINT_ARRAY_LENGTH - ), - itemsString = Array.prototype.join.call(limitedArray, ', '); + const constructorName = j$.fnNameFor(arr.constructor); + const limitedArray = Array.prototype.slice.call( + arr, + 0, + j$.MAX_PRETTY_PRINT_ARRAY_LENGTH + ); + let itemsString = Array.prototype.join.call(limitedArray, ', '); if (limitedArray.length !== arr.length) { itemsString += ', ...'; @@ -263,15 +261,10 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { }; SinglePrettyPrintRun.prototype.emitDomElement = function(el) { - var tagName = el.tagName.toLowerCase(), - attrs = el.attributes, - i, - len = attrs.length, - out = '<' + tagName, - attr; + const tagName = el.tagName.toLowerCase(); + let out = '<' + tagName; - for (i = 0; i < len; i++) { - attr = attrs[i]; + for (const attr of el.attributes) { out += ' ' + attr.name; if (attr.value !== '') { @@ -306,7 +299,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { value = Object.prototype.toString.call(value); } - var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length); + const result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length); this.length += result.value.length; this.stringParts.push(result.value); @@ -334,10 +327,8 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { MaxCharsReachedError.prototype = new Error(); function customFormat(value, customObjectFormatters) { - var i, result; - - for (i = 0; i < customObjectFormatters.length; i++) { - result = customObjectFormatters[i](value); + for (const formatter of customObjectFormatters) { + const result = formatter(value); if (result !== undefined) { return result; @@ -348,8 +339,11 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) { return function(customObjectFormatters) { customObjectFormatters = customObjectFormatters || []; - var pp = function(value) { - var prettyPrinter = new SinglePrettyPrintRun(customObjectFormatters, pp); + const pp = function(value) { + const prettyPrinter = new SinglePrettyPrintRun( + customObjectFormatters, + pp + ); prettyPrinter.format(value); return prettyPrinter.stringParts.join(''); }; diff --git a/src/core/matchers/DiffBuilder.js b/src/core/matchers/DiffBuilder.js index c8c0e497..50da9a69 100644 --- a/src/core/matchers/DiffBuilder.js +++ b/src/core/matchers/DiffBuilder.js @@ -1,10 +1,11 @@ getJasmineRequireObj().DiffBuilder = function(j$) { return function DiffBuilder(config) { - var prettyPrinter = (config || {}).prettyPrinter || j$.makePrettyPrinter(), - mismatches = new j$.MismatchTree(), - path = new j$.ObjectPath(), - actualRoot = undefined, - expectedRoot = undefined; + const prettyPrinter = + (config || {}).prettyPrinter || j$.makePrettyPrinter(); + const mismatches = new j$.MismatchTree(); + let path = new j$.ObjectPath(); + let actualRoot = undefined; + let expectedRoot = undefined; return { setRoots: function(actual, expected) { @@ -17,29 +18,24 @@ getJasmineRequireObj().DiffBuilder = function(j$) { }, getMessage: function() { - var messages = []; + const messages = []; mismatches.traverse(function(path, isLeaf, formatter) { - var actualCustom, - expectedCustom, - useCustom, - derefResult = dereferencePath( - path, - actualRoot, - expectedRoot, - prettyPrinter - ), - actual = derefResult.actual, - expected = derefResult.expected; + const { actual, expected } = dereferencePath( + path, + actualRoot, + expectedRoot, + prettyPrinter + ); if (formatter) { messages.push(formatter(actual, expected, path, prettyPrinter)); return true; } - actualCustom = prettyPrinter.customFormat_(actual); - expectedCustom = prettyPrinter.customFormat_(expected); - useCustom = !( + const actualCustom = prettyPrinter.customFormat_(actual); + const expectedCustom = prettyPrinter.customFormat_(expected); + const useCustom = !( j$.util.isUndefined(actualCustom) && j$.util.isUndefined(expectedCustom) ); @@ -64,7 +60,7 @@ getJasmineRequireObj().DiffBuilder = function(j$) { }, withPath: function(pathComponent, block) { - var oldPath = path; + const oldPath = path; path = path.add(pathComponent); block(); path = oldPath; @@ -98,18 +94,17 @@ getJasmineRequireObj().DiffBuilder = function(j$) { j$.isAsymmetricEqualityTester_(expected) && j$.isFunction_(expected.valuesForDiff_) ) { - var asymmetricResult = expected.valuesForDiff_(actual, pp); + const asymmetricResult = expected.valuesForDiff_(actual, pp); expected = asymmetricResult.self; actual = asymmetricResult.other; } } - var i; handleAsymmetricExpected(); - for (i = 0; i < objectPath.components.length; i++) { - actual = actual[objectPath.components[i]]; - expected = expected[objectPath.components[i]]; + for (const pc of objectPath.components) { + actual = actual[pc]; + expected = expected[pc]; handleAsymmetricExpected(); } diff --git a/src/core/matchers/MismatchTree.js b/src/core/matchers/MismatchTree.js index 3fdab889..9836b2d9 100644 --- a/src/core/matchers/MismatchTree.js +++ b/src/core/matchers/MismatchTree.js @@ -14,15 +14,13 @@ getJasmineRequireObj().MismatchTree = function(j$) { } MismatchTree.prototype.add = function(path, formatter) { - var key, child; - if (path.depth() === 0) { this.formatter = formatter; this.isMismatch = true; } else { - key = path.components[0]; + const key = path.components[0]; path = path.shift(); - child = this.child(key); + let child = this.child(key); if (!child) { child = new MismatchTree(this.path.add(key)); @@ -34,27 +32,22 @@ getJasmineRequireObj().MismatchTree = function(j$) { }; MismatchTree.prototype.traverse = function(visit) { - var i, - hasChildren = this.children.length > 0; + const hasChildren = this.children.length > 0; if (this.isMismatch || hasChildren) { if (visit(this.path, !hasChildren, this.formatter)) { - for (i = 0; i < this.children.length; i++) { - this.children[i].traverse(visit); + for (const child of this.children) { + child.traverse(visit); } } } }; MismatchTree.prototype.child = function(key) { - var i, pathEls; - - for (i = 0; i < this.children.length; i++) { - pathEls = this.children[i].path.components; - if (pathEls[pathEls.length - 1] === key) { - return this.children[i]; - } - } + return this.children.find(child => { + const pathEls = child.path.components; + return pathEls[pathEls.length - 1] === key; + }); }; return MismatchTree; diff --git a/src/core/matchers/ObjectPath.js b/src/core/matchers/ObjectPath.js index e287af19..f4225d5c 100644 --- a/src/core/matchers/ObjectPath.js +++ b/src/core/matchers/ObjectPath.js @@ -5,7 +5,7 @@ getJasmineRequireObj().ObjectPath = function(j$) { ObjectPath.prototype.toString = function() { if (this.components.length) { - return '$' + map(this.components, formatPropertyAccess).join(''); + return '$' + this.components.map(formatPropertyAccess).join(''); } else { return ''; } @@ -35,14 +35,6 @@ getJasmineRequireObj().ObjectPath = function(j$) { return "['" + prop + "']"; } - function map(array, fn) { - var results = []; - for (var i = 0; i < array.length; i++) { - results.push(fn(array[i])); - } - return results; - } - function isValidIdentifier(string) { return /^[A-Za-z\$_][A-Za-z0-9\$_]*$/.test(string); }