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

unexpected

Package Overview
Dependencies
Maintainers
6
Versions
330
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unexpected - npm Package Compare versions

Comparing version 12.0.4 to 13.0.0

70

build/lib/createTopLevelExpect.js

@@ -457,23 +457,7 @@ var createStandardErrorMessage = require('./createStandardErrorMessage');

var assertion;
if (tokens.length === 1 && typeof tokens[0] === 'string') {
if (!this._legacyTypelessAssertionWarned) {
console.warn(
'The typeless expect.addAssertion syntax is deprecated and will be removed in a future update\n' +
'Please refer to http://unexpected.js.org/api/addAssertion/'
);
this._legacyTypelessAssertionWarned = true;
}
assertion = {
subject: parseTypeToken('any'),
assertion: tokens[0],
args: [parseTypeToken('any*')],
};
} else {
assertion = {
subject: tokens[0],
assertion: tokens[1],
args: tokens.slice(2),
};
}
var assertion = {
subject: tokens[0],
assertion: tokens[1],
args: tokens.slice(2),
};

@@ -1096,2 +1080,7 @@ if (!Array.isArray(assertion.subject)) {

}
if (pluginName === 'unexpected-set') {
throw new Error(
'The unexpected-set plugin was pulled into Unexpected as of 13.0.0. This means that the plugin is no longer supported.'
);
}

@@ -1670,14 +1659,16 @@ this.installedPlugins.push(plugin);

this._assertTopLevelExpect();
var childExpect = createTopLevelExpect({
assertions: {},
types: [],
typeByName: {},
output: this.output.clone(),
format: this.outputFormat(),
installedPlugins: [],
});
var parent = (childExpect.parent = this);
var childExpect = createTopLevelExpect(
{
assertions: {},
types: [],
typeByName: {},
output: this.output.clone(),
format: this.outputFormat(),
installedPlugins: [],
},
this
);
childExpect.exportAssertion = function (testDescription, handler) {
parent.addAssertion(testDescription, handler, childExpect);
childExpect.parent.addAssertion(testDescription, handler, childExpect);
return this;

@@ -1690,7 +1681,7 @@ };

parent.addType(type, childExpect);
childExpect.parent.addType(type, childExpect);
return this;
};
childExpect.exportStyle = function (name, handler, allowRedefinition) {
parent.addStyle(
childExpect.parent.addStyle(
name,

@@ -2014,3 +2005,6 @@ function () {

function createTopLevelExpect(ref) {
function createTopLevelExpect(
ref,
parentExpect
) {
if ( ref === void 0 ) ref = {};

@@ -2030,3 +2024,8 @@ var assertions = ref.assertions; if ( assertions === void 0 ) assertions = {};

};
utils.setPrototypeOfOrExtend(expect, expectPrototype);
if (parentExpect) {
expect.parent = parentExpect;
utils.setPrototypeOfOrExtend(expect, parentExpect);
} else {
utils.setPrototypeOfOrExtend(expect, expectPrototype);
}

@@ -2041,2 +2040,3 @@ if (!output) {

_outputFormat: format,
_frozen: false,
assertions: assertions,

@@ -2043,0 +2043,0 @@ typeByName: typeByName,

@@ -1040,2 +1040,173 @@ var utils = require('./utils');

expect.addType({
name: 'Set',
base: 'object',
indent: true,
identify: function identify(obj) {
return obj instanceof Set;
},
equal: function equal(a, b, equal$1) {
if (a.size !== b.size) {
return false;
}
var unequal = false;
a.forEach(function (value) {
unequal = unequal || !b.has(value);
});
if (unequal) {
// Slow path
var bElements = [];
b.forEach(function (element) {
bElements.push(element);
});
unequal = false;
a.forEach(function (value) {
unequal =
unequal ||
(!b.has(value) &&
!bElements.some(function (bElement) { return equal$1(value, bElement); }));
});
}
return !unequal;
},
prefix: function prefix(output) {
return output.jsKeyword('new').sp().jsKeyword('Set').text('([');
},
suffix: function suffix(output) {
return output.text('])');
},
inspect: function inspect(set, depth, output, inspect$1) {
// Mostly copied from array-like's inspect:
var prefixOutput = this.prefix(output.clone(), set);
var suffixOutput = this.suffix(output.clone(), set);
if (set.size === 0) {
return output.append(prefixOutput).append(suffixOutput);
}
if (depth === 1 && set.size > 10) {
return output.append(prefixOutput).text('...').append(suffixOutput);
}
var inspectedItems = [];
set.forEach(function (item) {
inspectedItems.push(inspect$1(item));
});
var currentDepth = defaultDepth - Math.min(defaultDepth, depth);
var maxLineLength =
output.preferredWidth - 20 - currentDepth * output.indentationWidth - 2;
var width = 0;
var multipleLines = inspectedItems.some(function (o) {
if (o.isMultiline()) {
return true;
}
var size = o.size();
width += size.width;
return width > maxLineLength;
});
var type = this;
inspectedItems.forEach(function (inspectedItem, index) {
inspectedItem.amend(
type.delimiter(output.clone(), index, inspectedItems.length)
);
});
output.append(prefixOutput);
if (this.forceMultipleLines || multipleLines) {
if (!prefixOutput.isEmpty()) {
output.nl();
}
if (this.indent) {
output.indentLines();
}
inspectedItems.forEach(function (inspectedItem, index) {
output
.nl(index > 0 ? 1 : 0)
.i()
.block(inspectedItem);
});
if (this.indent) {
output.outdentLines();
}
if (!suffixOutput.isEmpty()) {
output.nl();
}
} else {
output.sp(prefixOutput.isEmpty() ? 0 : 1);
inspectedItems.forEach(function (inspectedItem, index) {
output.append(inspectedItem);
var lastIndex = index === inspectedItems.length - 1;
if (!lastIndex) {
output.sp();
}
});
output.sp(suffixOutput.isEmpty() ? 0 : 1);
}
output.append(suffixOutput);
},
diff: function diff(actual, expected, output, diff$1, inspect, equal) {
output.inline = true;
var prefixOutput = this.prefix(output.clone(), actual);
var suffixOutput = this.suffix(output.clone(), actual);
output.append(prefixOutput).nl(prefixOutput.isEmpty() ? 0 : 1);
if (this.indent) {
output.indentLines();
}
var type = this;
var index = 0;
var actualElements = [];
actual.forEach(function (element) {
actualElements.push(element);
});
var expectedElements = [];
expected.forEach(function (element) {
expectedElements.push(element);
});
actual.forEach(function (actualElement) {
output
.nl(index > 0 ? 1 : 0)
.i()
.block(function () {
this.appendInspected(actualElement);
type.delimiter(this, index, actual.size);
if (
!expected.has(actualElement) &&
!expectedElements.some(function (element) { return equal(element, actualElement); })
) {
this.sp().annotationBlock(function () {
this.error('should be removed');
});
}
});
index += 1;
});
expected.forEach(function (expectedElement) {
if (
!actual.has(expectedElement) &&
!actualElements.some(function (element) { return equal(element, expectedElement); })
) {
output
.nl(index > 0 ? 1 : 0)
.i()
.annotationBlock(function () {
this.error('missing').sp().appendInspected(expectedElement);
});
index += 1;
}
});
if (this.indent) {
output.outdentLines();
}
output.nl(suffixOutput.isEmpty() ? 0 : 1).append(suffixOutput);
return output;
},
});
expect.addType({
base: 'function',

@@ -1322,6 +1493,3 @@ name: 'expect.it',

inspect: function inspect(value, depth, output) {
return output
.code('BigInt(', 'javascript')
.jsNumber(value.toString())
.code(')', 'javascript');
return output.jsNumber(value.toString()).code('n', 'javascript');
},

@@ -1328,0 +1496,0 @@ });

@@ -423,23 +423,7 @@ const createStandardErrorMessage = require('./createStandardErrorMessage');

let assertion;
if (tokens.length === 1 && typeof tokens[0] === 'string') {
if (!this._legacyTypelessAssertionWarned) {
console.warn(
'The typeless expect.addAssertion syntax is deprecated and will be removed in a future update\n' +
'Please refer to http://unexpected.js.org/api/addAssertion/'
);
this._legacyTypelessAssertionWarned = true;
}
assertion = {
subject: parseTypeToken('any'),
assertion: tokens[0],
args: [parseTypeToken('any*')],
};
} else {
assertion = {
subject: tokens[0],
assertion: tokens[1],
args: tokens.slice(2),
};
}
const assertion = {
subject: tokens[0],
assertion: tokens[1],
args: tokens.slice(2),
};

@@ -1028,2 +1012,7 @@ if (!Array.isArray(assertion.subject)) {

}
if (pluginName === 'unexpected-set') {
throw new Error(
'The unexpected-set plugin was pulled into Unexpected as of 13.0.0. This means that the plugin is no longer supported.'
);
}

@@ -1589,14 +1578,16 @@ this.installedPlugins.push(plugin);

this._assertTopLevelExpect();
const childExpect = createTopLevelExpect({
assertions: {},
types: [],
typeByName: {},
output: this.output.clone(),
format: this.outputFormat(),
installedPlugins: [],
});
const parent = (childExpect.parent = this);
const childExpect = createTopLevelExpect(
{
assertions: {},
types: [],
typeByName: {},
output: this.output.clone(),
format: this.outputFormat(),
installedPlugins: [],
},
this
);
childExpect.exportAssertion = function (testDescription, handler) {
parent.addAssertion(testDescription, handler, childExpect);
childExpect.parent.addAssertion(testDescription, handler, childExpect);
return this;

@@ -1609,7 +1600,7 @@ };

parent.addType(type, childExpect);
childExpect.parent.addType(type, childExpect);
return this;
};
childExpect.exportStyle = function (name, handler, allowRedefinition) {
parent.addStyle(
childExpect.parent.addStyle(
name,

@@ -1914,14 +1905,22 @@ function (...args) {

function createTopLevelExpect({
assertions = {},
typeByName = { any: anyType },
types = [anyType],
output,
format = magicpen.defaultFormat,
installedPlugins = [],
} = {}) {
function createTopLevelExpect(
{
assertions = {},
typeByName = { any: anyType },
types = [anyType],
output,
format = magicpen.defaultFormat,
installedPlugins = [],
} = {},
parentExpect
) {
const expect = function (...args) {
return expect._expect(new Context(), args);
};
utils.setPrototypeOfOrExtend(expect, expectPrototype);
if (parentExpect) {
expect.parent = parentExpect;
utils.setPrototypeOfOrExtend(expect, parentExpect);
} else {
utils.setPrototypeOfOrExtend(expect, expectPrototype);
}

@@ -1936,2 +1935,3 @@ if (!output) {

_outputFormat: format,
_frozen: false,
assertions,

@@ -1938,0 +1938,0 @@ typeByName,

@@ -1032,2 +1032,173 @@ const utils = require('./utils');

expect.addType({
name: 'Set',
base: 'object',
indent: true,
identify(obj) {
return obj instanceof Set;
},
equal(a, b, equal) {
if (a.size !== b.size) {
return false;
}
let unequal = false;
a.forEach((value) => {
unequal = unequal || !b.has(value);
});
if (unequal) {
// Slow path
const bElements = [];
b.forEach((element) => {
bElements.push(element);
});
unequal = false;
a.forEach((value) => {
unequal =
unequal ||
(!b.has(value) &&
!bElements.some((bElement) => equal(value, bElement)));
});
}
return !unequal;
},
prefix(output) {
return output.jsKeyword('new').sp().jsKeyword('Set').text('([');
},
suffix(output) {
return output.text('])');
},
inspect(set, depth, output, inspect) {
// Mostly copied from array-like's inspect:
const prefixOutput = this.prefix(output.clone(), set);
const suffixOutput = this.suffix(output.clone(), set);
if (set.size === 0) {
return output.append(prefixOutput).append(suffixOutput);
}
if (depth === 1 && set.size > 10) {
return output.append(prefixOutput).text('...').append(suffixOutput);
}
const inspectedItems = [];
set.forEach((item) => {
inspectedItems.push(inspect(item));
});
const currentDepth = defaultDepth - Math.min(defaultDepth, depth);
const maxLineLength =
output.preferredWidth - 20 - currentDepth * output.indentationWidth - 2;
let width = 0;
const multipleLines = inspectedItems.some((o) => {
if (o.isMultiline()) {
return true;
}
const size = o.size();
width += size.width;
return width > maxLineLength;
});
const type = this;
inspectedItems.forEach((inspectedItem, index) => {
inspectedItem.amend(
type.delimiter(output.clone(), index, inspectedItems.length)
);
});
output.append(prefixOutput);
if (this.forceMultipleLines || multipleLines) {
if (!prefixOutput.isEmpty()) {
output.nl();
}
if (this.indent) {
output.indentLines();
}
inspectedItems.forEach((inspectedItem, index) => {
output
.nl(index > 0 ? 1 : 0)
.i()
.block(inspectedItem);
});
if (this.indent) {
output.outdentLines();
}
if (!suffixOutput.isEmpty()) {
output.nl();
}
} else {
output.sp(prefixOutput.isEmpty() ? 0 : 1);
inspectedItems.forEach((inspectedItem, index) => {
output.append(inspectedItem);
const lastIndex = index === inspectedItems.length - 1;
if (!lastIndex) {
output.sp();
}
});
output.sp(suffixOutput.isEmpty() ? 0 : 1);
}
output.append(suffixOutput);
},
diff(actual, expected, output, diff, inspect, equal) {
output.inline = true;
const prefixOutput = this.prefix(output.clone(), actual);
const suffixOutput = this.suffix(output.clone(), actual);
output.append(prefixOutput).nl(prefixOutput.isEmpty() ? 0 : 1);
if (this.indent) {
output.indentLines();
}
const type = this;
let index = 0;
const actualElements = [];
actual.forEach((element) => {
actualElements.push(element);
});
const expectedElements = [];
expected.forEach((element) => {
expectedElements.push(element);
});
actual.forEach((actualElement) => {
output
.nl(index > 0 ? 1 : 0)
.i()
.block(function () {
this.appendInspected(actualElement);
type.delimiter(this, index, actual.size);
if (
!expected.has(actualElement) &&
!expectedElements.some((element) => equal(element, actualElement))
) {
this.sp().annotationBlock(function () {
this.error('should be removed');
});
}
});
index += 1;
});
expected.forEach((expectedElement) => {
if (
!actual.has(expectedElement) &&
!actualElements.some((element) => equal(element, expectedElement))
) {
output
.nl(index > 0 ? 1 : 0)
.i()
.annotationBlock(function () {
this.error('missing').sp().appendInspected(expectedElement);
});
index += 1;
}
});
if (this.indent) {
output.outdentLines();
}
output.nl(suffixOutput.isEmpty() ? 0 : 1).append(suffixOutput);
return output;
},
});
expect.addType({
base: 'function',

@@ -1311,6 +1482,3 @@ name: 'expect.it',

inspect(value, depth, output) {
return output
.code('BigInt(', 'javascript')
.jsNumber(value.toString())
.code(')', 'javascript');
return output.jsNumber(value.toString()).code('n', 'javascript');
},

@@ -1317,0 +1485,0 @@ });

{
"name": "unexpected",
"version": "12.0.4",
"version": "13.0.0",
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>",

@@ -39,8 +39,8 @@ "keywords": [

"eslint-config-prettier": "^8.2.0",
"eslint-config-standard": "^16.0.2",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-markdown": "^1.0.0",
"eslint-plugin-markdown": "^2.2.1",
"eslint-plugin-mocha": "^10.0.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-n": "^15.1.0",
"eslint-plugin-promise": "^6.0.0",
"evaldown": "^1.3.0",

@@ -52,6 +52,6 @@ "find-node-modules": "^2.0.0",

"istanbul": "^0.4.5",
"jasmine": "~3.9.0",
"jasmine": "^4.1.0",
"jasmine-core": "^4.0.0",
"jest": "^26.6.3",
"karma": "6.3.9",
"karma": "^6.3.16",
"karma-browserstack-launcher": "1.6.0",

@@ -58,0 +58,0 @@ "karma-chrome-launcher": "3.1.0",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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