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

assertion-error-formatter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assertion-error-formatter - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

lib/helpers/canonicalize_test.js

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 3.0.0 (2019-08-20)
* drop support for Node 4, 6
* support Node 10, 12
# 2.0.1

@@ -2,0 +7,0 @@

18

lib/helpers/canonicalize.js

@@ -1,5 +0,5 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default =
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = canonicalize;var _has_property = _interopRequireDefault(require("./has_property"));
var _type = _interopRequireDefault(require("./type"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
canonicalize;var _has_property = require('./has_property');var _has_property2 = _interopRequireDefault(_has_property);var _type = require('./type');var _type2 = _interopRequireDefault(_type);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function canonicalize(value, stack) {
function canonicalize(value, stack) {
stack = stack || [];

@@ -9,3 +9,3 @@

stack.push(value);
var result = fn();
const result = fn();
stack.pop();

@@ -19,3 +19,3 @@ return result;

switch ((0, _type2.default)(value)) {
switch ((0, _type.default)(value)) {
case 'array':

@@ -28,3 +28,3 @@ return withStack(function () {

case 'function':
if (!(0, _has_property2.default)(value)) {
if (!(0, _has_property.default)(value)) {
return '[Function]';

@@ -35,4 +35,6 @@ }

return withStack(function () {
var canonicalizedObj = {};
Object.keys(value).sort().map(function (key) {
const canonicalizedObj = {};
Object.keys(value).
sort().
map(function (key) {
canonicalizedObj[key] = canonicalize(value[key], stack);

@@ -39,0 +41,0 @@ });

"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = hasProperty;function hasProperty(obj) {
for (var prop in obj) {
for (const prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {

@@ -4,0 +4,0 @@ return true;

@@ -1,19 +0,21 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default =
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = inlineDiff;var _diff = require("diff");
var _padRight = _interopRequireDefault(require("pad-right"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
function inlineDiff(actual, expected, colorFns) {
let msg = errorDiff(actual, expected, colorFns);
inlineDiff;var _diff = require('diff');var _padRight = require('pad-right');var _padRight2 = _interopRequireDefault(_padRight);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function inlineDiff(actual, expected, colorFns) {
var msg = errorDiff(actual, expected, colorFns);
// linenos
var lines = msg.split('\n');
if (lines.length > 4) {(function () {
var width = String(lines.length).length;
msg = lines.map(function (str, i) {
return (0, _padRight2.default)(i + 1, width, ' ') + '|' + ' ' + str;
}).join('\n');})();
const lines = msg.split('\n');
if (lines.length > 4) {
const width = String(lines.length).length;
msg = lines.
map(function (str, i) {
return (0, _padRight.default)(i + 1, width, ' ') + '|' + ' ' + str;
}).
join('\n');
}
// legend
msg = '\n ' +
msg =
'\n ' +
colorFns.diffRemoved('actual') +

@@ -29,5 +31,5 @@ ' ' +

function errorDiff(actual, expected, colorFns) {
return (0, _diff.diffWordsWithSpace)(actual, expected).map(function (str) {
return (0, _diff.diffWordsWithSpace)(actual, expected).
map(function (str) {
if (str.added) {

@@ -40,3 +42,4 @@ return colorFns.diffAdded(str.value);

return str.value;
}).join('');
}).
join('');
}

@@ -1,9 +0,8 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default =
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = jsonStringify;var _repeatString = _interopRequireDefault(require("repeat-string"));
var _type = _interopRequireDefault(require("./type"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
jsonStringify;var _repeatString = require('repeat-string');var _repeatString2 = _interopRequireDefault(_repeatString);var _type = require('./type');var _type2 = _interopRequireDefault(_type);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function jsonStringify(object, depth) {
function jsonStringify(object, depth) {
depth = depth || 1;
switch ((0, _type2.default)(object)) {
switch ((0, _type.default)(object)) {
case 'boolean':

@@ -38,11 +37,9 @@ case 'regexp':

function jsonStringifyBuffer(object, depth) {var _object$toJSON =
object.toJSON(),data = _object$toJSON.data;
function jsonStringifyBuffer(object, depth) {
const { data } = object.toJSON();
return '[Buffer: ' + jsonStringify(data, depth) + ']';
}
function jsonStringifyDate(object) {
var str = void 0;
let str;
if (isNaN(object.getTime())) {

@@ -56,16 +53,20 @@ str = object.toString();

function jsonStringifyProperties(object, depth) {
var space = 2 * depth;
var start = (0, _type2.default)(object) === 'array' ? '[' : '{';
var end = (0, _type2.default)(object) === 'array' ? ']' : '}';
var length = typeof object.length === 'number' ? object.length : Object.keys(object).length;
var addedProperties = 0;
var str = start;
const space = 2 * depth;
const start = (0, _type.default)(object) === 'array' ? '[' : '{';
const end = (0, _type.default)(object) === 'array' ? ']' : '}';
const length =
typeof object.length === 'number' ?
object.length :
Object.keys(object).length;
let addedProperties = 0;
let str = start;
for (var prop in object) {
for (const prop in object) {
if (Object.prototype.hasOwnProperty.call(object, prop)) {
addedProperties += 1;
str += '\n' + (0, _repeatString2.default)(' ', space) + (
(0, _type2.default)(object) === 'array' ? '' : '"' + prop + '": ') +
str +=
'\n' +
(0, _repeatString.default)(' ', space) + (
(0, _type.default)(object) === 'array' ? '' : '"' + prop + '": ') +
jsonStringify(object[prop], depth + 1) + (

@@ -77,3 +78,3 @@ addedProperties === length ? '' : ',');

if (str.length !== 1) {
str += '\n' + (0, _repeatString2.default)(' ', space - 2);
str += '\n' + (0, _repeatString.default)(' ', space - 2);
}

@@ -80,0 +81,0 @@

@@ -1,7 +0,6 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default =
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = stringify;var _canonicalize = _interopRequireDefault(require("./canonicalize"));
var _json_stringify = _interopRequireDefault(require("./json_stringify"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
stringify;var _canonicalize = require('./canonicalize');var _canonicalize2 = _interopRequireDefault(_canonicalize);var _json_stringify = require('./json_stringify');var _json_stringify2 = _interopRequireDefault(_json_stringify);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function stringify(value) {
return (0, _json_stringify2.default)((0, _canonicalize2.default)(value)).replace(/,(\n|$)/g, '$1');
function stringify(value) {
return (0, _json_stringify.default)((0, _canonicalize.default)(value)).replace(/,(\n|$)/g, '$1');
}

@@ -1,2 +0,2 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default = type;function type(value) {
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = type;function type(value) {
if (value === undefined) {

@@ -9,5 +9,6 @@ return 'undefined';

}
return Object.prototype.toString.call(value).
return Object.prototype.toString.
call(value).
replace(/^\[.+\s(.+?)\]$/, '$1').
toLowerCase();
}

@@ -1,5 +0,5 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default =
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = unifiedDiff;var _diff = require("diff");
unifiedDiff;var _diff = require('diff');function unifiedDiff(actual, expected, colorFns) {
var indent = ' ';
function unifiedDiff(actual, expected, colorFns) {
const indent = ' ';
function cleanUp(line) {

@@ -15,3 +15,3 @@ if (line.length === 0) {

}
if (line.match(/\@\@/)) {
if (line.match(/@@/)) {
return null;

@@ -27,9 +27,16 @@ }

}
var msg = (0, _diff.createPatch)('string', actual, expected);
var lines = msg.split('\n').splice(4);
return '\n' + indent +
colorFns.diffAdded('+ expected') + ' ' +
colorFns.diffRemoved('- actual') +
'\n\n' +
lines.map(cleanUp).filter(notBlank).join('\n');
const msg = (0, _diff.createPatch)('string', actual, expected);
const lines = msg.split('\n').splice(4);
return (
'\n' +
indent +
colorFns.diffAdded('+ expected') +
' ' +
colorFns.diffRemoved('- actual') +
'\n\n' +
lines.
map(cleanUp).
filter(notBlank).
join('\n'));
}

@@ -1,13 +0,11 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.format = format;var _inline_diff = _interopRequireDefault(require("./helpers/inline_diff"));
var _stringify = _interopRequireDefault(require("./helpers/stringify"));
var _type = _interopRequireDefault(require("./helpers/type"));
var _unified_diff = _interopRequireDefault(require("./helpers/unified_diff"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
function identity(x) {
return x;
}
format = format;var _inline_diff = require('./helpers/inline_diff');var _inline_diff2 = _interopRequireDefault(_inline_diff);var _stringify = require('./helpers/stringify');var _stringify2 = _interopRequireDefault(_stringify);var _type = require('./helpers/type');var _type2 = _interopRequireDefault(_type);var _unified_diff = require('./helpers/unified_diff');var _unified_diff2 = _interopRequireDefault(_unified_diff);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function identity(x) {return x;}function format(err, options) {
function format(err, options) {
if (!options) {

@@ -19,3 +17,5 @@ options = {};

}
['diffAdded', 'diffRemoved', 'errorMessage', 'errorStack'].forEach(function (key) {
['diffAdded', 'diffRemoved', 'errorMessage', 'errorStack'].forEach(function (
key)
{
if (!options.colorFns[key]) {

@@ -26,3 +26,3 @@ options.colorFns[key] = identity;

var message = void 0;
let message;
if (err.message && typeof err.message.toString === 'function') {

@@ -38,8 +38,8 @@ message = err.message + '';

var stack = err.stack || message;
var startOfMessageIndex = stack.indexOf(message);
let stack = err.stack || message;
const startOfMessageIndex = stack.indexOf(message);
if (startOfMessageIndex === -1) {
stack = '\n' + stack;
} else {
var endOfMessageIndex = startOfMessageIndex + message.length;
const endOfMessageIndex = startOfMessageIndex + message.length;
message = stack.slice(0, endOfMessageIndex);

@@ -53,18 +53,22 @@ stack = stack.slice(endOfMessageIndex); // remove message from stack

var actual = err.actual;
var expected = err.expected;
let actual = err.actual;
let expected = err.expected;
if (err.showDiff !== false && (0, _type2.default)(actual) === (0, _type2.default)(expected) && expected !== undefined) {
if (!((0, _type2.default)(actual) === 'string' && (0, _type2.default)(expected) === 'string')) {
actual = (0, _stringify2.default)(actual);
expected = (0, _stringify2.default)(expected);
if (
err.showDiff !== false &&
(0, _type.default)(actual) === (0, _type.default)(expected) &&
expected !== undefined)
{
if (!((0, _type.default)(actual) === 'string' && (0, _type.default)(expected) === 'string')) {
actual = (0, _stringify.default)(actual);
expected = (0, _stringify.default)(expected);
}
var match = message.match(/^([^:]+): expected/);
const match = message.match(/^([^:]+): expected/);
message = options.colorFns.errorMessage(match ? match[1] : message);
if (options.inlineDiff) {
message += (0, _inline_diff2.default)(actual, expected, options.colorFns);
message += (0, _inline_diff.default)(actual, expected, options.colorFns);
} else {
message += (0, _unified_diff2.default)(actual, expected, options.colorFns);
message += (0, _unified_diff.default)(actual, expected, options.colorFns);
}

@@ -71,0 +75,0 @@ } else {

{
"name": "assertion-error-formatter",
"version": "2.0.1",
"version": "3.0.0",
"main": "lib/index.js",

@@ -28,17 +28,25 @@ "scripts": {

"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-eslint": "^7.1.1",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"dependency-lint": "^4.3.0",
"eslint": "^3.7.0",
"eslint-plugin-babel": "^4.0.0",
"mocha": "^3.2.0",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0"
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"babel-eslint": "^10.0.2",
"chai": "^4.2.0",
"dependency-lint": "^6.0.0",
"eslint": "~6.1.0",
"eslint-config-prettier": "^6.1.0",
"eslint-config-standard": "^14.0.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^6.2.0",
"prettier": "^1.18.2",
"sinon": "^7.4.1",
"sinon-chai": "^3.3.0"
},
"dependencies": {
"diff": "^3.0.0",
"diff": "^4.0.1",
"pad-right": "^0.2.2",

@@ -45,0 +53,0 @@ "repeat-string": "^1.6.1"

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