find-test-names
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "find-test-names", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Given a Mocha / Cypress spec file, returns the list of suite and test names", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -27,2 +27,12 @@ const acorn = require('acorn') | ||
// extracts the test name from the literal or template literal node | ||
const extractTestName = (node) => { | ||
if (node.type === 'TemplateLiteral') { | ||
return node.quasis.map((q) => q.value.cooked.trim()).join(' ') | ||
} else if (node.type === 'Literal') { | ||
return node.value | ||
} | ||
throw new Error(`Unsupported node type: ${node.type}`) | ||
} | ||
/** | ||
@@ -51,4 +61,5 @@ * Returns all suite and test names found in the given JavaScript | ||
if (isDescribe(node)) { | ||
const name = extractTestName(node.arguments[0]) | ||
const suiteInfo = { | ||
name: node.arguments[0].value, | ||
name, | ||
} | ||
@@ -60,7 +71,8 @@ | ||
} | ||
suiteNames.push(suiteInfo.name) | ||
suiteNames.push(name) | ||
tests.push(suiteInfo) | ||
} else if (isIt(node)) { | ||
const name = extractTestName(node.arguments[0]) | ||
const testInfo = { | ||
name: node.arguments[0].value, | ||
name, | ||
} | ||
@@ -72,3 +84,3 @@ | ||
} | ||
testNames.push(testInfo.name) | ||
testNames.push(name) | ||
tests.push(testInfo) | ||
@@ -75,0 +87,0 @@ } |
6850
101