New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

find-test-names

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-test-names - npm Package Compare versions

Comparing version 1.22.3 to 1.23.0

6

package.json
{
"name": "find-test-names",
"version": "1.22.3",
"version": "1.23.0",
"description": "Given a Mocha / Cypress spec file, returns the list of suite and test names",

@@ -47,6 +47,6 @@ "main": "src",

"devDependencies": {
"ava": "5.1.0",
"ava": "5.1.1",
"common-tags": "1.8.2",
"husky": "7.0.4",
"prettier": "2.8.1",
"prettier": "2.8.3",
"semantic-release": "20.0.2",

@@ -53,0 +53,0 @@ "stop-only": "3.1.2"

@@ -27,2 +27,8 @@ const babel = require('@babel/parser')

/**
* Finds "tags" field in the test node.
* Could be a single string or an array of strings.
*
* it('name', {tags: '@smoke'}, () => ...)
*/
const getTags = (source, node) => {

@@ -50,2 +56,30 @@ if (node.arguments.length < 2) {

/**
* Finds "onlyTags" field in the test node.
* Could be a single string or an array of strings.
*
* it('name', {onlyTags: '@smoke'}, () => ...)
*/
const getOnlyTags = (source, node) => {
if (node.arguments.length < 2) {
// pending tests don't have tags
return
}
if (node.arguments[1].type === 'ObjectExpression') {
// extract any possible tags
const tags = node.arguments[1].properties.find((node) => {
return node.key.name === 'onlyTags'
})
if (tags) {
if (tags.value.type === 'ArrayExpression') {
const tagsText = source.slice(tags.start, tags.end)
return eval(tagsText)
} else if (tags.value.type === 'Literal') {
return [tags.value.value]
}
}
}
}
// extracts the test name from the literal or template literal node

@@ -126,5 +160,11 @@ // if the test name is a variable, returns undefined

const onlyTags = getOnlyTags(source, node)
if (Array.isArray(onlyTags) && onlyTags.length > 0) {
suiteInfo.onlyTags = onlyTags
}
const suite = {
name,
tags: suiteInfo.tags,
onlyTags: suiteInfo.onlyTags,
pending: suiteInfo.pending,

@@ -170,2 +210,6 @@ type: 'suite',

}
const onlyTags = getOnlyTags(source, node)
if (Array.isArray(onlyTags) && onlyTags.length > 0) {
testInfo.onlyTags = onlyTags
}

@@ -175,2 +219,3 @@ const test = {

tags: testInfo.tags,
onlyTags: testInfo.onlyTags,
pending: testInfo.pending,

@@ -422,2 +467,11 @@ type: 'test',

function collectSuiteOnlyTagsUp(suite) {
const tags = []
while (suite) {
tags.push(...(suite.onlyTags || []))
suite = suite.parent
}
return tags
}
/**

@@ -494,2 +548,3 @@ * Synchronous tree walker, calls the given callback for each test.

const ownTags = [].concat(test.tags || [])
const ownOnlyTags = [].concat(test.onlyTags || [])

@@ -502,2 +557,8 @@ // also consider the effective tags by traveling up

test.effectiveTags = uniqueTags.sort()
// collect the "only tags" up the suite parents
const suiteOnlyTags = collectSuiteOnlyTagsUp(parentSuite)
const allOnlyTags = [...ownOnlyTags, ...suiteOnlyTags]
const uniqueOnlyTags = [...new Set(allOnlyTags)]
test.onlyTags = [...new Set(uniqueOnlyTags)].sort()
})

@@ -744,3 +805,6 @@

}
testTags[test.fullName] = { effectiveTags: test.effectiveTags }
testTags[test.fullName] = {
effectiveTags: test.effectiveTags,
onlyTags: test.onlyTags,
}
})

@@ -747,0 +811,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc