Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assert-diff

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert-diff - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

test/example-passing-tests.js

49

lib/assert-diff.js

@@ -1,26 +0,26 @@

var assert = require('assert-plus')
var jdiff = require('json-diff')
var assert = require('assert-plus');
var jdiff = require('json-diff');
var opts = {strict: false}
module.exports = exports = function(options) {
opts = options
return module.exports
function AssertDiff() {
assert.ok.apply(assert.ok, arguments);
}
Object.keys(assert).forEach(function(key) {
module.exports[key] = function() {
assert[key].apply(assert[key], arguments)
}
})
AssertDiff.options = { strict: true };
exports.deepEqual = function() {
Object.keys(assert).forEach(function(k) {
AssertDiff[k] = function() {
assert[k].apply(assert[k], arguments);
};
});
AssertDiff.deepEqual = function() {
try {
assert.deepEqual.apply(assert.deepEqual, arguments)
assert.deepEqual.apply(assert.deepEqual, arguments);
} catch (e) {
e.message = addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual))
delete e.expected
delete e.actual
throw e
e.message = addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual));
delete e.expected;
delete e.actualQ;
throw e;
}
if (opts.strict && jdiff.diff(arguments[0], arguments[1])) {
if (AssertDiff.options.strict && jdiff.diff(arguments[0], arguments[1])) {
throw new assert.AssertionError({

@@ -31,10 +31,13 @@ message: addDiffToMessage(arguments[2], jdiff.diffString(arguments[0], arguments[1])),

}
}
};
function addDiffToMessage(message, diff) {
var msg = message ? message : ''
var resetCliColorAttributes = '\u001b[m'
return msg + resetCliColorAttributes + '\n' + diff
var msg = message ? message : '';
var resetCliColorAttributes = '\u001b[m';
return msg + resetCliColorAttributes + '\n' + diff;
}
exports.deepEqualOrig = assert.deepEqual
AssertDiff.deepEqualOrig = assert.deepEqual;
module.exports = AssertDiff;
{
"name": "assert-diff",
"description": "Drop-in replacement for assert to give diff on deepEqual.",
"keywords": ["assert", "diff", "deepEqual", "object", "array", "strict"],
"keywords": [
"assert",
"diff",
"deepEqual",
"object",
"array",
"strict"
],
"author": "Antti Mattila <pihvi@live.com>",
"repository": "git://github.com/pihvi/assert-diff",
"version": "0.0.4",
"version": "1.0.0",
"main": "./lib/assert-diff.js",
"license": "Apache 2.0",
"dependencies": {
"assert-plus": "0.1.4",
"assert-plus": "0.1.5",
"json-diff": "0.3.1"
},
"devDependencies": {
"mocha": "1.10.0"
"mocha": "2.1.0"
},
"scripts": {
"test": "mocha"
"test": "mocha test/example-passing-tests.js",
"start": "mocha"
}
}

@@ -25,3 +25,4 @@ Drop-in replacement for assert to give colored diff on command-line with deepEqual.

```javascript
var assert = require('assert-diff')({strict: true})
var assert = require('assert-diff')
assert.options.strict = true

@@ -36,3 +37,11 @@ it('strict diff deep equal', function() {

## Release notes ##
### 1.0.0 Feb 18, 2015 ###
- Support assert in constructor e.g. assert(true)
### 0.0.x before 2015 ###
- Initial implementation
## License ##
Apache 2.0

@@ -1,37 +0,41 @@

var assert = require('./../lib/assert-diff')
var assertOrig = require('assert')
var assert = require('./../lib/assert-diff');
var assertOrig = require('assert');
it('diff deep equal array', function() {
assert.string("yea")
assert.deepEqual([22, "loi", {pow: true}], [22, "lol", {pow: true}])
assert.string('yea');
assert.deepEqual([22, 'loi', {pow: true}], [22, 'lol', {pow: true}]);
})
it('original deep equal array', function() {
assertOrig.deepEqual([22, "loi", {pow: true}], [22, "lol", {pow: true}])
assertOrig.deepEqual([22, 'loi', {pow: true}], [22, 'lol', {pow: true}]);
})
it('diff deep equal string', function() {
assert.deepEqual("tomato", "tomeito")
assert.deepEqual('tomato', 'tomeito');
})
it('original deep equal string', function() {
assertOrig.deepEqual("tomato", "tomeito", "hahaa")
assertOrig.deepEqual('tomato', 'tomeito', 'hahaa');
})
it('diff deep equal', function() {
assert.deepEqual({pow: "boom", same: true, foo: 2}, {same: true, bar: 2, pow: "bang"})
assert.deepEqual({pow: 'boom', same: true, foo: 2}, {same: true, bar: 2, pow: 'bang'});
})
it('original deep equal', function() {
assertOrig.deepEqual({pow: "boom", same: true, foo: 2}, {same: true, bar: 2, pow: "bang"})
assertOrig.deepEqual({pow: 'boom', same: true, foo: 2}, {same: true, bar: 2, pow: 'bang'});
})
it('diff deep equal with message', function() {
assert.deepEqual({pow: "boom", same: true, foo: 2}, {same: true, bar: 2, pow: "bang"}, "this should fail")
assert.deepEqual({pow: 'boom', same: true, foo: 2}, {same: true, bar: 2, pow: 'bang'}, 'this should fail');
})
it('strict diff deep equal', function() {
assert.deepEqual({a: 1, b: 2}, {a: true, b: "2"}, "this should not fail")
assert({strict: true}).deepEqual({a: 1}, {a: 1}, "this should not fail")
assert({strict: true}).deepEqual({a: 1, b: 2}, {a: true, b: "2"}, "this should fail")
assert.deepEqual({a: 1}, {a: 1}, 'this should not fail');
assert.options.strict = false;
assert.deepEqual({a: 1, b: 2}, {a: true, b: '2'}, 'this should not fail');
assert.options.strict = true;
assert.deepEqual({a: 1, b: 2}, {a: true, b: '2'}, 'this should fail');
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc