find-test-names is a JavaScript utility library designed to parse Mocha and Cypress test specification files to extract suite and test names, including associated tags and structural hierarchy. Currently at version 1.29.19, it maintains a steady release cadence with frequent minor updates, primarily for dependency bumps and bug fixes. The library differentiates itself by offering deep static analysis of test files, supporting advanced features like effective tag computation (propagating tags from parent suites to child tests), filtering tests by tags, and extracting pending tests. It handles modern JavaScript features, including JSX and TypeScript syntax, by leveraging `@babel/parser`. This enables automation scenarios where understanding test metadata without executing the tests is crucial, such as dynamic test selection or reporting.
npm install find-test-namesVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a test file, extracting its full structure, computing effective tags for each test, and filtering tests by specific tags. It also shows the simpler flat list extraction.
Ensure your Node.js and `find-test-names` versions are up-to-date. If errors persist with new syntax, consider slightly older syntax or a custom Babel configuration if the library allowed (which it currently does not for parsing).
Use string literals directly for tags or ensure tag variables are local `const` declarations and used via direct reference or literal property access (e.g., `{ tags: MY_TAG }` or `{ tags: TAGS.FOO }`).For full traceability, use string literals for test titles. If dynamic names are necessary, be aware of the `<unknown test>` label and rely on other metadata like tags for identification.
Review any file globbing patterns used with `findEffectiveTestTagsIn` or similar file-system-interacting functions if unexpected changes in file discovery occur after updating to `v1.29.19`.
Update `find-test-names` to the latest version. If the error persists, check if the syntax is extremely new or non-standard. Consider simplifying the problematic code segment or reporting an issue to the library maintainers.
Ensure you are using named imports/requires: `import { getTestNames } from 'find-test-names'` for ESM or `const { getTestNames } = require('find-test-names')` for CommonJS.Always use `import { ... } from 'find-test-names'` in ESM projects. Ensure Node.js version supports package `exports` map (Node.js 12+). Check `package.json` for `"type": "module"` and correct import syntax.