find-test-names
Advanced tools
Comparing version 1.13.0 to 1.14.0
{ | ||
"name": "find-test-names", | ||
"version": "1.13.0", | ||
"version": "1.14.0", | ||
"description": "Given a Mocha / Cypress spec file, returns the list of suite and test names", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -343,2 +343,11 @@ const babel = require('@babel/parser') | ||
function collectSuiteTagsUp(suite) { | ||
const tags = [] | ||
while (suite) { | ||
tags.push(...(suite.tags || [])) | ||
suite = suite.parent | ||
} | ||
return tags | ||
} | ||
/** | ||
@@ -349,9 +358,9 @@ * Synchronous tree walker, calls the given callback for each test. | ||
*/ | ||
function visitEachTest(structure, fn) { | ||
function visitEachTest(structure, fn, parentSuite) { | ||
structure.forEach((t) => { | ||
if (t.type === 'suite') { | ||
visitEachTest(t.tests, fn) | ||
visitEachTest(t.tests, fn, t) | ||
visitEachTest(t.suites, fn) | ||
} else { | ||
fn(t) | ||
fn(t, parentSuite) | ||
} | ||
@@ -361,2 +370,12 @@ }) | ||
function visitEachNode(structure, fn, parentSuite) { | ||
structure.forEach((t) => { | ||
fn(t, parentSuite) | ||
if (t.type === 'suite') { | ||
visitEachNode(t.tests, fn, t) | ||
visitEachNode(t.suites, fn, t) | ||
} | ||
}) | ||
} | ||
/** | ||
@@ -368,9 +387,8 @@ * Counts the tags found on the tests. | ||
function countTags(structure) { | ||
setParentSuite(structure) | ||
const tags = {} | ||
visitEachTest(structure, (test) => { | ||
if (!test.tags) { | ||
return | ||
} | ||
visitEachTest(structure, (test, parentSuite) => { | ||
// normalize the tags to be an array of strings | ||
const list = [].concat(test.tags) | ||
const list = [].concat(test.tags || []) | ||
list.forEach((tag) => { | ||
@@ -383,2 +401,13 @@ if (!(tag in tags)) { | ||
}) | ||
// also consider the effective tags by traveling up | ||
// the parent chain of suites | ||
const suiteTags = collectSuiteTagsUp(parentSuite) | ||
suiteTags.forEach((tag) => { | ||
if (!(tag in tags)) { | ||
tags[tag] = 1 | ||
} else { | ||
tags[tag] += 1 | ||
} | ||
}) | ||
}) | ||
@@ -389,2 +418,10 @@ | ||
function setParentSuite(structure) { | ||
visitEachNode(structure, (test, parentSuite) => { | ||
if (parentSuite) { | ||
test.parent = parentSuite | ||
} | ||
}) | ||
} | ||
/** | ||
@@ -530,2 +567,4 @@ * Returns all suite and test names found in the given JavaScript | ||
countTags, | ||
visitEachNode, | ||
setParentSuite, | ||
} |
24005
626