jest-test-each
Advanced tools
Comparing version 0.8.4 to 0.8.5
104
dist/tree.js
@@ -10,3 +10,3 @@ "use strict"; | ||
const name = name_1.getName([obj], maxTestNameLength); | ||
return { | ||
const node = { | ||
name: name.name, | ||
@@ -20,2 +20,3 @@ parent, | ||
}; | ||
return node; | ||
}; | ||
@@ -33,3 +34,3 @@ const mergeNodes = (node, child, maxTestNameLength) => { | ||
previousData, | ||
tests: [...child.tests], | ||
tests: [...node.tests, ...child.tests], | ||
children: [...child.children], | ||
@@ -61,63 +62,46 @@ }; | ||
const populateNode = (parent, nextLevel = 0) => { | ||
for (const [levelNum, cases] of levels2.entries()) { | ||
if (nextLevel !== levelNum) { | ||
continue; | ||
const levelNum = nextLevel; | ||
const cases = levels2.length > 0 ? levels2[levelNum] : []; | ||
const previousData = Object.assign({}, parent.fullData); | ||
const normalized = typeof cases === 'function' ? cases(previousData) : cases; | ||
if (normalized.length === 0 && !previousData.isEmpty) { | ||
errors.push({ | ||
msg: 'every .each should have non empty cases.\nIf it is expected mark cases with "isEmpty:true"', | ||
test: typeof cases === 'function' ? `${cases}` : `${JSON.stringify(cases)}`, | ||
details: `${typeof cases === 'function' | ||
? `each '${cases}' evaluated to an empty array.\n\tArgs {${JSON.stringify(previousData)}}` | ||
: ''}`, | ||
}); | ||
} | ||
if (levelNum === levels2.length - 1) { | ||
normalized.forEach((p) => { | ||
const test_ = createTest(p, parent, maxTestNameLength); | ||
const test = onEachTest ? onEachTest(test_) : test_; | ||
parent.tests.push(test); | ||
}); | ||
return; | ||
} | ||
normalized.forEach((p) => { | ||
var _a; | ||
const node = createNode(p, maxTestNameLength, parent); | ||
populateNode(node, levelNum + 1); | ||
if (node.children.length === 1 && node.tests.length === 0) { | ||
const newNode = mergeNodes(node, node.children[0], maxTestNameLength); | ||
node.tests = newNode.tests; | ||
node.children = newNode.children; | ||
node.previousData = newNode.previousData; | ||
node.fullData = newNode.fullData; | ||
node.currentData = newNode.currentData; | ||
node.name = newNode.name; | ||
} | ||
const previousData = Object.assign({}, parent.fullData); | ||
const normalized = typeof cases === 'function' ? cases(previousData) : cases; | ||
if (normalized.length === 0 && !previousData.isEmpty) { | ||
errors.push({ | ||
msg: 'every .each should have non empty cases.\nIf it is expected mark cases with "isEmpty:true"', | ||
test: typeof cases === 'function' ? `${cases}` : `${JSON.stringify(cases)}`, | ||
details: `${typeof cases === 'function' | ||
? `each '${cases}' evaluated to an empty array.\n\tArgs {${JSON.stringify(previousData)}}` | ||
: ''}`, | ||
}); | ||
if (node.tests.length === 1 && node.children.length === 0) { | ||
const test = mergeNodeAndTest(node, node.tests[0], maxTestNameLength); | ||
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.tests.push(test)) || parent.tests.push(test); | ||
return; | ||
} | ||
if (levelNum < levels2.length - 1) { | ||
if (normalized.length === 1) { | ||
const obj = Object.assign({}, normalized[0]); | ||
const node = createNode(obj, maxTestNameLength, parent); | ||
populateNode(node, levelNum + 1); | ||
if (node.children.length > 0 || node.tests.length > 0) { | ||
const merged = mergeNodes(parent, node, maxTestNameLength); | ||
if (merged.tests.length === 1) { | ||
parent.tests.push(mergeNodeAndTest(merged, merged.tests[0], maxTestNameLength)); | ||
} | ||
else { | ||
if (parent.parent) { | ||
parent.parent.children.push(merged); | ||
} | ||
else { | ||
parent.children.push(merged); | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
normalized.forEach((p) => { | ||
const child = createNode(p, maxTestNameLength, parent); | ||
populateNode(child, levelNum + 1); | ||
if (child.children.length > 1 || child.tests.length > 1) { | ||
parent.children.push(child); | ||
} | ||
else if (child.children.length === 1) { | ||
parent.children.push(mergeNodes(child, child.children[0], maxTestNameLength)); | ||
} | ||
else { | ||
child.tests.forEach((test) => { | ||
parent.tests.push(mergeNodeAndTest(child, test, maxTestNameLength)); | ||
}); | ||
} | ||
}); | ||
} | ||
if (node.tests.length === 0 && node.children.length === 0) { | ||
return; | ||
} | ||
else { | ||
normalized.forEach((p) => { | ||
const test_ = createTest(p, parent, maxTestNameLength); | ||
const test = onEachTest ? onEachTest(test_) : test_; | ||
parent.tests.push(test); | ||
}); | ||
} | ||
} | ||
parent.children.push(node); | ||
}); | ||
}; | ||
@@ -124,0 +108,0 @@ populateNode(root); |
{ | ||
"name": "jest-test-each", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "run parametrised tests easily [typesafe] without text tables or arrays of arrays.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
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
Sorry, the diff of this file is not supported yet
191061
1565