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 1.0.2 to 2.0.0

18

lib/helpers/inline_diff.js

@@ -5,4 +5,4 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.default =

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, options) {
var msg = errorDiff(actual, expected, options);
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);

@@ -19,8 +19,8 @@ // linenos

// legend
msg = '\n ' +
options.colorDiffRemoved('actual') +
msg = '\n ' +
colorFns.diffRemoved('actual') +
' ' +
options.colorDiffAdded('expected') +
colorFns.diffAdded('expected') +
'\n\n' +
msg.replace(/^/gm, ' ') +
msg.replace(/^/gm, ' ') +
'\n';

@@ -32,9 +32,9 @@

function errorDiff(actual, expected, options) {
function errorDiff(actual, expected, colorFns) {
return (0, _diff.diffWordsWithSpace)(actual, expected).map(function (str) {
if (str.added) {
return options.colorDiffAdded(str.value);
return colorFns.diffAdded(str.value);
}
if (str.removed) {
return options.colorDiffRemoved(str.value);
return colorFns.diffRemoved(str.value);
}

@@ -41,0 +41,0 @@ return str.value;

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

@@ -10,6 +10,6 @@ if (line.length === 0) {

if (line[0] === '+') {
return indent + options.colorDiffAdded(line);
return indent + colorFns.diffAdded(line);
}
if (line[0] === '-') {
return indent + options.colorDiffRemoved(line);
return indent + colorFns.diffRemoved(line);
}

@@ -29,7 +29,7 @@ if (line.match(/\@\@/)) {

var lines = msg.split('\n').splice(4);
return '\n ' +
options.colorDiffAdded('+ expected') + ' ' +
options.colorDiffRemoved('- actual') +
return '\n' + indent +
colorFns.diffAdded('+ expected') + ' ' +
colorFns.diffRemoved('- actual') +
'\n\n' +
lines.map(cleanUp).filter(notBlank).join('\n');
}

@@ -16,11 +16,10 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.

}
if (!options.colorDiffAdded) {
options.colorDiffAdded = identity;
if (!options.colorFns) {
options.colorFns = {};
}
if (!options.colorDiffRemoved) {
options.colorDiffRemoved = identity;
}
if (!options.colorErrorMessage) {
options.colorErrorMessage = identity;
}
['diffAdded', 'diffRemoved', 'errorMessage', 'errorStack'].forEach(function (key) {
if (!options.colorFns[key]) {
options.colorFns[key] = identity;
}
});

@@ -33,3 +32,3 @@ var message = void 0;

} else {
message = '';
message = err;
}

@@ -42,3 +41,3 @@

message = stack.slice(0, endOfMessageIndex);
stack = stack.slice(endOfMessageIndex + 1); // remove message from stack
stack = stack.slice(endOfMessageIndex); // remove message from stack
}

@@ -60,13 +59,15 @@

var match = message.match(/^([^:]+): expected/);
message = options.colorErrorMessage(match ? match[1] : message);
message = options.colorFns.errorMessage(match ? match[1] : message);
if (options.inlineDiff) {
message += (0, _inline_diff2.default)(actual, expected, options);
message += (0, _inline_diff2.default)(actual, expected, options.colorFns);
} else {
message += (0, _unified_diff2.default)(actual, expected, options);
message += (0, _unified_diff2.default)(actual, expected, options.colorFns);
}
} else {
message = options.colorFns.errorMessage(message);
}
if (stack) {
stack = stack.replace(/^/gm, ' '); // indent stack trace
stack = options.colorFns.errorStack(stack);
}

@@ -73,0 +74,0 @@

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

@@ -5,0 +5,0 @@ "scripts": {

@@ -18,9 +18,4 @@ # Node Assertion Error Formatter

* `options`: An object with the following keys:
* `colorDiffAdded(str)`: function (default: identity)
* colorizes a string, used in diffs to highlight the added lines
* `colorDiffRemoved(str)`: function (default: identity)
* colorizes a string, used in diffs to highlight the removed lines
* `colorErrorMessage(str)`: function (default: identity)
* colorizes a string, used for the error message
* `colorFns`: An object with the keys 'diffAdded', 'diffRemoved', 'errorMessage', 'errorStack'. The values are functions to colorize a string, each defaults to identity.
* `inlineDiff`: boolean (default: false)
* toggle between inline and unified diffs
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