Socket
Socket
Sign inDemoInstall

karma-jasmine-diff-reporter

Package Overview
Dependencies
142
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.0 to 0.6.1

1

CHANGELOG.md
### Changelog
- 0.6.1 - Sort object properties before comparing
- 0.6.0 - Add a color option to highlight whitespaces independently

@@ -4,0 +5,0 @@ - 0.5.0 - Added JSON option. Fixed pretty print for Karma 1.x

@@ -20,4 +20,28 @@ describe('Matcher', function () {

it('should sort object props', function () {
var a = {
bar: 42,
qux: 'fox',
foo: {
c: 2,
a: 0,
b: 1,
}
};
var b = {
far: 50,
qux: 'fox',
extra: 'extra',
bar: 42,
foo: {
b: 1,
c: 2,
a: 0,
}
};
expect(a).toEqual(b);
});
});
});

2

package.json
{
"name": "karma-jasmine-diff-reporter",
"version": "0.6.0",
"version": "0.6.1",
"description": "Karma reporter to highlight diffs of failed equality expectations for Jasmine",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -23,2 +23,19 @@ (function (window) {

// https://github.com/mradionov/karma-jasmine-diff-reporter/issues/16
// Objects might have their properties specified in different order, it might
// result in a not very correct diff, when the same prop appears in different
// places of compared objects. Fix it by soring object properties in
// alphabetical order.
// NOTE: Order of props is not guaranteed in JS,
// see http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order
// But according to: http://stackoverflow.com/a/29622653/1573638
// "most of the browser's implementations values in objects are stored
// in the order in which they were added" - we can use it, it won't harm anyway
function sortObject(obj) {
return Object.keys(obj).sort().reduce(function (result, key) {
result[key] = obj[key];
return result;
}, {});
}
var toString = Object.prototype.toString;

@@ -30,3 +47,7 @@

function isPlainObject(value) {
return toString.call(value) === '[object Object]';
}
function ppJSONPatched(j$) {

@@ -47,2 +68,6 @@ return function(value) {

if (isPlainObject(value)) {
return sortObject(value);
}
return value;

@@ -49,0 +74,0 @@ });

@@ -22,4 +22,5 @@ // Most of the code is originaly written by Jasmine developers.

// Version of pretty print module taken from Jamsine 2.3.4
// At the moment, the only thing patched is a method
// Patched methods:
// StringPrettyPrinter.prototype.emitString
// StringPrettyPrinter.prototype.emitObject

@@ -42,2 +43,18 @@ window.jasmine.pp = ppPatched(window.jasmine);

// https://github.com/mradionov/karma-jasmine-diff-reporter/issues/16
// Objects might have their properties specified in different order, it might
// result in a not very correct diff, when the same prop appears in different
// places of compared objects. Fix it by soring object properties in
// alphabetical order.
// NOTE: Order of props is not guaranteed in JS,
// see http://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order
// But according to: http://stackoverflow.com/a/29622653/1573638
// "most of the browser's implementations values in objects are stored
// in the order in which they were added" - we can use it, it won't harm anyway
function sortObject(obj) {
return Object.keys(obj).sort().reduce(function (result, key) {
result[key] = obj[key];
return result;
}, {});
}

@@ -172,3 +189,5 @@ function ppPatched(j$) {

this.iterateObject(obj, function(property, isGetter) {
var sortedObj = sortObject(obj);
this.iterateObject(sortedObj, function(property, isGetter) {
if (first) {

@@ -180,3 +199,3 @@ first = false;

self.formatProperty(obj, property, isGetter);
self.formatProperty(sortedObj, property, isGetter);
});

@@ -183,0 +202,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc