find-test-names
Advanced tools
Comparing version 1.16.0 to 1.17.0
{ | ||
"name": "find-test-names", | ||
"version": "1.16.0", | ||
"version": "1.17.0", | ||
"description": "Given a Mocha / Cypress spec file, returns the list of suite and test names", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -68,2 +68,19 @@ # find-test-names [](https://github.com/bahmutov/find-test-names/actions/workflows/ci.yml) | ||
### filterByEffectiveTags | ||
Once you `setEffectiveTags`, you can filter all tests by an effective tag. For example, to fid all tests with the given tag: | ||
```js | ||
const { | ||
getTestNames, | ||
setEffectiveTags, | ||
filterByEffectiveTags, | ||
} = require('find-test-names') | ||
const result = getTestNames(source, true) | ||
setEffectiveTags(result.structure) | ||
const tests = filterByEffectiveTags(result.structure, ['@one']) | ||
``` | ||
Returns individual test objects. | ||
### Bin | ||
@@ -70,0 +87,0 @@ |
@@ -457,2 +457,17 @@ const babel = require('@babel/parser') | ||
/** | ||
* Visits each individual test in the structure and checks if it | ||
* has any effective tags from the given list. | ||
*/ | ||
function filterByEffectiveTags(structure, tags) { | ||
const filteredTests = [] | ||
visitEachTest(structure, (test) => { | ||
const hasTag = tags.some((tag) => test.effectiveTags.includes(tag)) | ||
if (hasTag) { | ||
filteredTests.push(test) | ||
} | ||
}) | ||
return filteredTests | ||
} | ||
function setParentSuite(structure) { | ||
@@ -611,2 +626,3 @@ visitEachNode(structure, (test, parentSuite) => { | ||
setEffectiveTags, | ||
filterByEffectiveTags, | ||
} |
27408
684
190