Gathering detailed insights and metrics for find-cypress-specs
Gathering detailed insights and metrics for find-cypress-specs
Gathering detailed insights and metrics for find-cypress-specs
Gathering detailed insights and metrics for find-cypress-specs
npm install find-cypress-specs
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
38 Stars
405 Commits
12 Forks
4 Watching
58 Branches
7 Contributors
Updated on 21 Nov 2024
JavaScript (97.23%)
TypeScript (2.77%)
Cumulative downloads
Total Downloads
Last day
-13.9%
44,465
Compared to previous day
Last week
2.3%
259,749
Compared to previous week
Last month
22.1%
1,042,668
Compared to previous month
Last year
301.6%
8,569,923
Compared to previous year
Find Cypress spec files using the config settings
1$ npx find-cypress-specs 2# prints all spec files separated by a comma 3cypress/e2e/spec.js,cypress/e2e/featureA/user.js
Supports JS and TS specs
You can count the number of specs found
1$ npx find-cypress-specs --count 22
By default, it finds the E2E specs and tests. You can find component specs using --component
CLI option
$ npx find-cypress-specs --component
By default, this module simply prints all spec filenames. You can add --branch
parameter to only print the specs changed against that origin/branch
.
1$ npx find-cypress-specs --branch main 2# prints only some specs, the ones that have changed against the "origin/main"
You can grep all test titles (only the test titles, not the suite names) and find the list of specs
1$ npx find-cypress-specs --grep "works, needs"
This will find all specs with tests that have "works" in the title or "needs" in the title and output the list of specs. If you use --set-gha-outputs
and GitHub Actions, it sets the outputs grepSpecs
and grepSpecsN
.
If we find all the changed specs to run, we might need to decide how many machines we need. We can do a rough job by specifying the number of specs per machine plus the max number.
$ npx find-cypress-specs --branch main --specs-per-machine 4 --max-machines 5
For now, it is only useful when setting the GHA outputs.
If you add --set-gha-outputs
command line switch, then the number of changed specs and the comma-separated file list will be set as GH Actions outputs changedSpecsN
and changedSpecs
. See pr.yml for example
1- name: Print specs changed against the parent of this branch 🌳 2 # and set GitHub Actions output 3 id: step1 4 run: node ./bin/find --branch main --parent --set-gha-outputs 5 6- name: Print set outputs 7 run: echo ${{ steps.step1.outputs.changedSpecsN }} ${{ steps.step1.outputs.changedSpecs }}
If you set the number of machines, it will set the output machinesNeeded
You can output changes specs by using the parameter --gha-summary
When dealing with a long-term branch, you do not want to see the changed files in the main branch. Instead, you want to only consider the specs changed in the current branch all the way to its parent commit. You can pass the flag --parent
to only pick the modified and added specs.
1$ npx find-cypress-specs --branch main --parent 2# same as 3# git diff --name-only --diff-filter=AMR $(git merge-base origin/main HEAD)..
Note: to get the changed files, we need to fetch the repo, see pr.yml
$ checkout
$ git fetch
$ npx find-cypress-specs --branch main --parent
Imagine you open a pull request and only change something in an utils.js
file used by other specs. Which specs should you run? By default --branch main --parent
would not find any changed specs, so no specs would execute, and you will have to run all specs just to be safe. This program has a mode --trace-imports <subfolder>
which uses spec-change to inspect JS/TS files and find dependencies between them. Thus it can discover that when utils.js
changes, the specs that import './utils'
or require('./utils')
should also be considered modified.
$ npx find-cypress-specs --branch main --parent --trace-imports cypress
Note: the argument is the subfolder name to limit the number of files to inspect when tracing the imports.
You can time how long tracing takes by adding option --time-trace
to the command line arguments. You can also saved traced dependencies using --cache-trace
argument. Next time the dependencies will be loaded from the file without recomputing. This is convenient on CI to avoid recomputing them. For example, if you need the number of affected files and their filenames
# get the number of affected specs
$ npx find-cypress-specs --branch main --parent --trace-imports cypress --cache-trace --count
# quickly get the affected specs without recomputing the dependencies
$ npx find-cypress-specs --branch main --parent --trace-imports cypress --cache-trace
The cached trace will be saved in file deps.json
, you probably want to Git ignore it.
You can limit the number of added traced files using the --max-added-traced-specs <N>
parameter. This avoids ALL specs added when you change some common utility that many specs import.
You can print just the number of changed specs
1$ npx find-cypress-specs --branch main --count 2# prints the number of spec files changed against the branch "origin/main" 35
You can filter all changed specs and only report (and count) the specs that have changed AND include the given tag(s)
1$ npx find-cypress-specs --branch main --tagged @user,@preview 2# prints only some specs, the ones that have changed against the "origin/main" 3# and that have any tests or suites inside tagged "@user" or "@preview"
You can set the list and number of specs with tags into GHA outputs
1$ npx find-cypress-specs --branch main --tagged @user,@preview --set-gha-outputs
The number of found specs will be set as taggedSpecsN
and the list will be set as taggedSpecs
.
Let's say we changed 2 specs that have tests tagged @user
. We can output the count by adding --count
option
1$ npx find-cypress-specs --branch main --tagged @user --count 22
You can print each spec file with the suite and test names inside of it (found using find-test-names)
1$ npx find-cypress-specs --names 2# prints something like 3 4cypress/e2e/spec.js (2 tests) 5└─ parent suite [@main] 6 ├─ works well enough 7 └─ inner suite 8 └─ shows something [@user] 9 10cypress/e2e/featureA/user.js (2 tests, 1 pending) 11├─ works 12└⊙ needs to be written 13 14found 2 specs (4 tests, 1 pending)
Where the tags are listed inside [ ... ]
(see @bahmutov/cy-grep) and the pending tests are marked with ⊙
character.
Required tags are marked with [[ ... ]]
.
You can print the results in JSON format using --json
or -j
option.
You can print the tests in Markdown format using --markdown
or --md
option
Spec |
---|
foo/a/spec.cy.js (3 tests) |
suite / test 1 |
suite / test 2 |
suite / test 3 |
foo/b/spec.cy.js (1 test) |
another / test / test 1 |
You can count tags attached to the individual tests using --tags
arguments
$ npx find-cypress-specs --tags
# prints the tags table sorted by tag
Tag Tests
----- ----------
@sign 1
@user 2
Each tag count includes the tests that use the tag directly, and the effective tags applied from the parent suites, both tags
and requiredTags
.
You can print the results in JSON format using --json
or -j
option.
1$ npx find-cypress-specs --names --tagged <single tag> 2# finds all specs and tests, then filters the output by a single tag
1$ npx find-cypress-specs --names --tagged <tag1>,<tag2>,<tag3>,... 2# finds all specs and tests, then filters the output showing all tests 3# tagged with tag1 or tag2 or tag3 or ...
$ npx find-cypress-specs --tagged <single tag>
# finds all specs and tests, then filters the output showing only the file names associated with the tests
# cypress/e2e/spec.cy.js,cypress/e2e/featureA/user.cy.ts
If you pass an empty string argument like --tagged ''
, an empty list is returned.
You can print the number of found tagged specs by adding --count
argument
$ npx find-cypress-specs --tagged <single tag> --count
3
$ npx find-cypress-specs --tagged <tag1>,<tag2>,<tag3>,...
# finds all specs and tests, then filters the output showing only the file names associated with the tests
# tagged with tag1 or tag2 or tag3 or ...
You can show only the tests marked with "it.skip" which are called "pending" according to Mocha / Cypress terminology.
1$ npx find-cypress-specs --names --pending 2# --skipped is an alias to --pending 3$ npx find-cypress-specs --names --skipped 4# prints and counts only the pending tests 5cypress/e2e/featureA/user.cy.ts (1 test, 1 pending) 6└⊙ needs to be written [@alpha] 7 8found 1 spec (1 test, 1 pending)
$ npx find-cypress-specs --names --skipped
Prints each spec that has skipped tests.
You can see the total number of E2E and component tests
$ npx find-cypress-specs --test-counts
4 e2e tests, 2 component tests
You can set or update a badge in README with test counts by adding the --update-badge
argument
$ npx find-cypress-specs --test-counts --update-badge
4 e2e tests, 2 component tests
⚠️ Could not find test count badge
Insert new badge on the first line
saving updated readme with new test counts
See the badges.yml workflow
Prints the single number with the count of skipped tests
$ npx find-cypress-specs --names --skipped --count
5
If the project uses TypeScript and cypress.config.ts
then this module uses tsx to load the config and fetch the spec pattern.
If you are using import
keyword in your cypress.config.ts
you might get an error like this:
import { defineConfig } from 'cypress';
^^^^^^
SyntaxError: Cannot use import statement outside a module
In that case, add to your tsconfig.json
file the ts-node
block:
1{ 2 "ts-node": { 3 "compilerOptions": { 4 "module": "commonjs" 5 } 6 } 7}
See example in bahmutov/test-todomvc-using-app-actions.
Tip: read my blog post Convert Cypress Specs from JavaScript to TypeScript.
If you want to use a custom Cypress config, pass it via the environment variable CYPRESS_CONFIG_FILE
$ CYPRESS_CONFIG_FILE=path/to/cypress.config.js npx find-cypres-specs ...
You can return absolute filenames to the found specs
1getSpecs(config, 'e2e|component', true)
Cypress uses the resolved configuration values to find the spec files to run. It searches the integrationFolder
for all patterns listed in testFiles
and removes any files matching the ignoreTestFiles
patterns.
You can see how Cypress finds the specs using DEBUG=cypress:cli,cypress:server:specs
environment variable to see verbose logs. The logic should be in the file packages/server/lib/util/specs.ts
in the repo cypress-io/cypress
Run the utility with environment variable DEBUG=find-cypress-specs
to see the verbose logs
Finding tests in the individual specs uses find-test-names so you might want to enable debugging both modules at once:
$ DEBUG=find-cypress-specs,find-test-names npx find-cypress-specs --names
To debug finding changed specs against a branch, use find-cypress-specs:git
$ DEBUG=find-cypress-specs:git npx find-cypress-specs --branch main
You can use this module via its NPM module API.
1const { getSpecs } = require('find-cypress-specs') 2// somewhere in the cypress.config.js 3setupNodeEvents(on, config) { 4 const specs = getSpecs(config) 5 // specs is a list of filenames 6}
You can pass the config
object to the getSpecs
method. If there is no config
parameter, it will read the config file automatically.
1const specs = getSpecs({
2 e2e: {
3 specPattern: '*/e2e/featureA/*.cy.ts',
4 },
5})
6// ['cypress/e2e/featureA/spec.cy.ts']
Returns an object with individual test information
1const { getTests } = require('find-cypress-specs') 2const { jsonResults, tagTestCounts } = getTests() 3// jsonResults is an object 4// with an entry per spec file
See get-tests.js for details and examples.
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
License: MIT - do anything with the code, but don't blame me if it does not work.
Support: if you find any problems with this module, email / tweet / open issue on Github
Copyright (c) 2022 Gleb Bahmutov <gleb.bahmutov@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
No security vulnerabilities found.