find-test-names
Advanced tools
Comparing version 1.19.0 to 1.20.0
{ | ||
"name": "find-test-names", | ||
"version": "1.19.0", | ||
"version": "1.20.0", | ||
"description": "Given a Mocha / Cypress spec file, returns the list of suite and test names", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -91,2 +91,6 @@ # find-test-names [](https://github.com/bahmutov/find-test-names/actions/workflows/ci.yml) | ||
### findEffectiveTestTags | ||
Returns a single object with full test titles as keys. For each key, the value is the list of effective tags. See the [find-effective-tags.js](./test/find-effective-tags.js) spec file. | ||
### Bin | ||
@@ -93,0 +97,0 @@ |
@@ -18,4 +18,4 @@ const babel = require('@babel/parser') | ||
const isIt = (node) => | ||
node.type === 'CallExpression' && | ||
( node.callee.name === 'it' || node.callee.name === 'specify' ) | ||
node.type === 'CallExpression' && | ||
(node.callee.name === 'it' || node.callee.name === 'specify') | ||
@@ -25,3 +25,3 @@ const isItSkip = (node) => | ||
node.callee.type === 'MemberExpression' && | ||
( node.callee.object.name === 'it' || node.callee.object.name === 'specify' ) && | ||
(node.callee.object.name === 'it' || node.callee.object.name === 'specify') && | ||
node.callee.property.name === 'skip' | ||
@@ -691,2 +691,29 @@ | ||
/** Given the test source code, finds all tests | ||
* and returns a single object with all test titles. | ||
* Each key is the full test title. | ||
* The value is a list of effective tags for this test. | ||
*/ | ||
function findEffectiveTestTags(source) { | ||
if (typeof source !== 'string') { | ||
throw new Error('Expected a string source') | ||
} | ||
const result = getTestNames(source, true) | ||
setEffectiveTags(result.structure) | ||
const testTags = {} | ||
visitEachTest(result.structure, (test, parentSuite) => { | ||
// console.log(test) | ||
if (typeof test.fullName !== 'string') { | ||
console.error(test) | ||
throw new Error('Cannot find the full name for test') | ||
} | ||
testTags[test.fullName] = test.effectiveTags | ||
}) | ||
// console.log(testTags) | ||
return testTags | ||
} | ||
module.exports = { | ||
@@ -702,2 +729,3 @@ getTestNames, | ||
filterByEffectiveTags, | ||
findEffectiveTestTags, | ||
} |
30884
772
200