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

jest-each

Package Overview
Dependencies
Maintainers
2
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-each - npm Package Compare versions

Comparing version 24.0.0-alpha.8 to 24.0.0-alpha.9

366

build/bind.js

@@ -6,73 +6,42 @@ 'use strict';

});
exports.default = void 0;
var _slicedToArray = (function() {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (
var _i = arr[Symbol.iterator](), _s;
!(_n = (_s = _i.next()).done);
_n = true
) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i['return']) _i['return']();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return function(arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError(
'Invalid attempt to destructure non-iterable instance'
);
}
function _util() {
const data = _interopRequireDefault(require('util'));
_util = function _util() {
return data;
};
})();
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
var _util;
function _load_util() {
return (_util = _interopRequireDefault(require('util')));
return data;
}
var _chalk;
function _chalk() {
const data = _interopRequireDefault(require('chalk'));
function _load_chalk() {
return (_chalk = _interopRequireDefault(require('chalk')));
_chalk = function _chalk() {
return data;
};
return data;
}
var _prettyFormat;
function _prettyFormat() {
const data = _interopRequireDefault(require('pretty-format'));
function _load_prettyFormat() {
return (_prettyFormat = _interopRequireDefault(require('pretty-format')));
_prettyFormat = function _prettyFormat() {
return data;
};
return data;
}
var _jestUtil;
function _jestUtil() {
const data = require('jest-util');
function _load_jestUtil() {
return (_jestUtil = require('jest-util'));
_jestUtil = function _jestUtil() {
return data;
};
return data;
}

@@ -84,18 +53,14 @@

function _toArray(arr) {
return Array.isArray(arr) ? arr : Array.from(arr);
}
/**
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
const EXPECTED_COLOR = _chalk().default.green;
function _toConsumableArray(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++)
arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
}
const RECEIVED_COLOR = _chalk().default.red;
const EXPECTED_COLOR = (_chalk || _load_chalk()).default.green;
const RECEIVED_COLOR = (_chalk || _load_chalk()).default.red;
const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp%]/g;

@@ -105,28 +70,25 @@ const PRETTY_PLACEHOLDER = '%p';

exports.default = function(cb) {
let supportsDone =
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
return function() {
for (
var _len = arguments.length, args = Array(_len), _key = 0;
_key < _len;
_key++
) {
args[_key] = arguments[_key];
}
var _default = (cb, supportsDone = true) => (...args) =>
function eachBind(title, test, timeout) {
if (args.length === 1) {
const tableArg = args[0];
return function eachBind(title, test, timeout) {
if (args.length === 1) {
var _args = _slicedToArray(args, 1);
if (!Array.isArray(tableArg)) {
const error = new (_jestUtil()).ErrorWithStack(
'`.each` must be called with an Array or Tagged Template Literal.\n\n' +
`Instead was called with: ${(0, _prettyFormat().default)(tableArg, {
maxDepth: 1,
min: true
})}\n`,
eachBind
);
return cb(title, () => {
throw error;
});
}
const tableArg = _args[0];
if (!Array.isArray(tableArg)) {
const error = new (_jestUtil || _load_jestUtil()).ErrorWithStack(
'`.each` must be called with an Array or Tagged Template Literal.\n\n' +
`Instead was called with: ${(0,
(_prettyFormat || _load_prettyFormat()).default)(tableArg, {
maxDepth: 1,
min: true
})}\n`,
if (isTaggedTemplateLiteral(tableArg)) {
if (isEmptyString(tableArg[0])) {
const error = new (_jestUtil()).ErrorWithStack(
'Error: `.each` called with an empty Tagged Template Literal of table data.\n',
eachBind

@@ -139,71 +101,16 @@ );

if (isTaggedTemplateLiteral(tableArg)) {
if (isEmptyString(tableArg[0])) {
const error = new (_jestUtil || _load_jestUtil()).ErrorWithStack(
'Error: `.each` called with an empty Tagged Template Literal of table data.\n',
eachBind
);
return cb(title, () => {
throw error;
});
}
const error = new (_jestUtil || _load_jestUtil()).ErrorWithStack(
'Error: `.each` called with a Tagged Template Literal with no data, remember to interpolate with ${expression} syntax.\n',
eachBind
);
return cb(title, () => {
throw error;
});
}
if (isEmptyTable(tableArg)) {
const error = new (_jestUtil || _load_jestUtil()).ErrorWithStack(
'Error: `.each` called with an empty Array of table data.\n',
eachBind
);
return cb(title, () => {
throw error;
});
}
const table = tableArg.every(Array.isArray)
? tableArg
: tableArg.map(entry => [entry]);
return table.forEach((row, i) =>
cb(
arrayFormat.apply(
undefined,
[title, i].concat(_toConsumableArray(row))
),
applyRestParams(supportsDone, row, test),
timeout
)
const error = new (_jestUtil()).ErrorWithStack(
'Error: `.each` called with a Tagged Template Literal with no data, remember to interpolate with ${expression} syntax.\n',
eachBind
);
return cb(title, () => {
throw error;
});
}
const templateStrings = args[0];
const data = args.slice(1);
const keys = getHeadingKeys(templateStrings[0]);
const table = buildTable(data, keys.length, keys);
const missingData = data.length % keys.length;
if (missingData > 0) {
const error = new (_jestUtil || _load_jestUtil()).ErrorWithStack(
'Not enough arguments supplied for given headings:\n' +
EXPECTED_COLOR(keys.join(' | ')) +
'\n\n' +
'Received:\n' +
RECEIVED_COLOR(
(0, (_prettyFormat || _load_prettyFormat()).default)(data)
) +
'\n\n' +
`Missing ${RECEIVED_COLOR(missingData.toString())} ${pluralize(
'argument',
missingData
)}`,
if (isEmptyTable(tableArg)) {
const error = new (_jestUtil()).ErrorWithStack(
'Error: `.each` called with an empty Array of table data.\n',
eachBind
);
return cb(title, () => {

@@ -214,15 +121,54 @@ throw error;

return table.forEach(row =>
const table = tableArg.every(Array.isArray)
? tableArg
: tableArg.map(entry => [entry]);
return table.forEach((row, i) =>
cb(
interpolate(title, row),
applyObjectParams(supportsDone, row, test),
arrayFormat(title, i, ...row),
applyRestParams(supportsDone, row, test),
timeout
)
);
};
}
const templateStrings = args[0];
const data = args.slice(1);
const keys = getHeadingKeys(templateStrings[0]);
const table = buildTable(data, keys.length, keys);
const missingData = data.length % keys.length;
if (missingData > 0) {
const error = new (_jestUtil()).ErrorWithStack(
'Not enough arguments supplied for given headings:\n' +
EXPECTED_COLOR(keys.join(' | ')) +
'\n\n' +
'Received:\n' +
RECEIVED_COLOR((0, _prettyFormat().default)(data)) +
'\n\n' +
`Missing ${RECEIVED_COLOR(missingData.toString())} ${pluralize(
'argument',
missingData
)}`,
eachBind
);
return cb(title, () => {
throw error;
});
}
return table.forEach(row =>
cb(
interpolate(title, row),
applyObjectParams(supportsDone, row, test),
timeout
)
);
};
};
exports.default = _default;
const isTaggedTemplateLiteral = array => array.raw !== undefined;
const isEmptyTable = table => table.length === 0;
const isEmptyString = str => typeof str === 'string' && str.trim() === '';

@@ -237,49 +183,37 @@

const arrayFormat = function(title, rowIndex) {
for (
var _len2 = arguments.length,
args = Array(_len2 > 2 ? _len2 - 2 : 0),
_key2 = 2;
_key2 < _len2;
_key2++
) {
args[_key2 - 2] = arguments[_key2];
}
const arrayFormat = (title, rowIndex, ...args) => {
const placeholders = title.match(SUPPORTED_PLACEHOLDERS) || [];
const prettyIndexes = getPrettyIndexes(placeholders);
var _args$reduce = args.reduce(
(acc, arg, index) => {
if (prettyIndexes.indexOf(index) !== -1) {
const _args$reduce = args.reduce(
(acc, arg, index) => {
if (prettyIndexes.indexOf(index) !== -1) {
return {
args: acc.args,
title: acc.title.replace(
PRETTY_PLACEHOLDER,
(0, _prettyFormat().default)(arg, {
maxDepth: 1,
min: true
})
)
};
}
return {
args: acc.args,
title: acc.title.replace(
PRETTY_PLACEHOLDER,
(0, (_prettyFormat || _load_prettyFormat()).default)(arg, {
maxDepth: 1,
min: true
})
)
args: acc.args.concat([arg]),
title: acc.title
};
},
{
args: [],
title
}
return {
args: acc.args.concat([arg]),
title: acc.title
};
},
{args: [], title: title}
);
const prettyTitle = _args$reduce.title,
),
prettyTitle = _args$reduce.title,
remainingArgs = _args$reduce.args;
return (_util || _load_util()).default.format.apply(
(_util || _load_util()).default,
[prettyTitle.replace(INDEX_PLACEHOLDER, rowIndex.toString())].concat(
_toConsumableArray(
remainingArgs.slice(0, placeholders.length - prettyIndexes.length)
)
)
return _util().default.format(
prettyTitle.replace(INDEX_PLACEHOLDER, rowIndex.toString()),
...remainingArgs.slice(0, placeholders.length - prettyIndexes.length)
);

@@ -290,4 +224,4 @@ };

supportsDone && params.length < test.length
? done => test.apply(undefined, _toConsumableArray(params).concat([done]))
: () => test.apply(undefined, _toConsumableArray(params));
? done => test(...params, done)
: () => test(...params);

@@ -297,7 +231,12 @@ const getHeadingKeys = headings => headings.replace(/\s/g, '').split('|');

const buildTable = (data, rowSize, keys) =>
Array.from({length: data.length / rowSize})
Array.from({
length: data.length / rowSize
})
.map((_, index) => data.slice(index * rowSize, index * rowSize + rowSize))
.map(row =>
row.reduce(
(acc, value, index) => Object.assign({}, acc, {[keys[index]]: value}),
(acc, value, index) =>
Object.assign({}, acc, {
[keys[index]]: value
}),
{}

@@ -315,3 +254,3 @@ )

match,
(0, (_prettyFormat || _load_prettyFormat()).default)(value, {
(0, _prettyFormat().default)(value, {
maxDepth: 1,

@@ -333,10 +272,5 @@ min: true

const getPath = (o, _ref) => {
var _ref2 = _toArray(_ref);
let head = _ref2[0],
tail = _ref2.slice(1);
const getPath = (o, [head, ...tail]) => {
if (!head || !o.hasOwnProperty || !o.hasOwnProperty(head)) return o;
return getPath(o[head], tail);
};

@@ -6,10 +6,12 @@ 'use strict';

});
exports.bind = undefined;
Object.defineProperty(exports, 'bind', {
enumerable: true,
get: function get() {
return _bind.default;
}
});
exports.default = void 0;
var _bind;
var _bind = _interopRequireDefault(require('./bind'));
function _load_bind() {
return (_bind = _interopRequireDefault(require('./bind')));
}
function _interopRequireDefault(obj) {

@@ -19,89 +21,2 @@ return obj && obj.__esModule ? obj : {default: obj};

const install = function(g) {
for (
var _len = arguments.length,
args = Array(_len > 1 ? _len - 1 : 0),
_key = 1;
_key < _len;
_key++
) {
args[_key - 1] = arguments[_key];
}
const test = (title, test, timeout) =>
(0, (_bind || _load_bind()).default)(g.test).apply(undefined, args)(
title,
test,
timeout
);
test.skip = (0, (_bind || _load_bind()).default)(g.test.skip).apply(
undefined,
args
);
test.only = (0, (_bind || _load_bind()).default)(g.test.only).apply(
undefined,
args
);
const it = (title, test, timeout) =>
(0, (_bind || _load_bind()).default)(g.it).apply(undefined, args)(
title,
test,
timeout
);
it.skip = (0, (_bind || _load_bind()).default)(g.it.skip).apply(
undefined,
args
);
it.only = (0, (_bind || _load_bind()).default)(g.it.only).apply(
undefined,
args
);
const xit = (0, (_bind || _load_bind()).default)(g.xit).apply(
undefined,
args
);
const fit = (0, (_bind || _load_bind()).default)(g.fit).apply(
undefined,
args
);
const xtest = (0, (_bind || _load_bind()).default)(g.xtest).apply(
undefined,
args
);
const describe = (title, suite, timeout) =>
(0, (_bind || _load_bind()).default)(g.describe, false).apply(
undefined,
args
)(title, suite, timeout);
describe.skip = (0, (_bind || _load_bind()).default)(
g.describe.skip,
false
).apply(undefined, args);
describe.only = (0, (_bind || _load_bind()).default)(
g.describe.only,
false
).apply(undefined, args);
const fdescribe = (0, (_bind || _load_bind()).default)(
g.fdescribe,
false
).apply(undefined, args);
const xdescribe = (0, (_bind || _load_bind()).default)(
g.xdescribe,
false
).apply(undefined, args);
return {
describe: describe,
fdescribe: fdescribe,
fit: fit,
it: it,
test: test,
xdescribe: xdescribe,
xit: xit,
xtest: xtest
};
};
/**

@@ -115,29 +30,42 @@ * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

*/
const install = (g, ...args) => {
const test = (title, test, timeout) =>
(0, _bind.default)(g.test)(...args)(title, test, timeout);
const each = function() {
for (
var _len2 = arguments.length, args = Array(_len2), _key2 = 0;
_key2 < _len2;
_key2++
) {
args[_key2] = arguments[_key2];
}
test.skip = (0, _bind.default)(g.test.skip)(...args);
test.only = (0, _bind.default)(g.test.only)(...args);
return install.apply(undefined, [global].concat(args));
};
const it = (title, test, timeout) =>
(0, _bind.default)(g.it)(...args)(title, test, timeout);
each.withGlobal = g =>
function() {
for (
var _len3 = arguments.length, args = Array(_len3), _key3 = 0;
_key3 < _len3;
_key3++
) {
args[_key3] = arguments[_key3];
}
it.skip = (0, _bind.default)(g.it.skip)(...args);
it.only = (0, _bind.default)(g.it.only)(...args);
const xit = (0, _bind.default)(g.xit)(...args);
const fit = (0, _bind.default)(g.fit)(...args);
const xtest = (0, _bind.default)(g.xtest)(...args);
return install.apply(undefined, [g].concat(args));
const describe = (title, suite, timeout) =>
(0, _bind.default)(g.describe, false)(...args)(title, suite, timeout);
describe.skip = (0, _bind.default)(g.describe.skip, false)(...args);
describe.only = (0, _bind.default)(g.describe.only, false)(...args);
const fdescribe = (0, _bind.default)(g.fdescribe, false)(...args);
const xdescribe = (0, _bind.default)(g.xdescribe, false)(...args);
return {
describe,
fdescribe,
fit,
it,
test,
xdescribe,
xit,
xtest
};
};
exports.bind = (_bind || _load_bind()).default;
exports.default = each;
const each = (...args) => install(global, ...args);
each.withGlobal = g => (...args) => install(g, ...args);
var _default = each;
exports.default = _default;
{
"name": "jest-each",
"version": "24.0.0-alpha.8",
"version": "24.0.0-alpha.9",
"description": "Parameterised tests for Jest",

@@ -20,4 +20,4 @@ "main": "build/index.js",

"chalk": "^2.0.1",
"jest-util": "^23.4.0",
"pretty-format": "^24.0.0-alpha.8"
"jest-util": "^24.0.0-alpha.9",
"pretty-format": "^24.0.0-alpha.9"
},

@@ -27,3 +27,3 @@ "engines": {

},
"gitHead": "700e0dadb85f5dc8ff5dac6c7e98956690049734"
"gitHead": "c7caa7ba5904d0c61e586694cde5f536639e4afc"
}
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