nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.85k stars 2.38k forks source link

Support passing a list of test files to the Jest executor #20462

Open cmparsons opened 1 year ago

cmparsons commented 1 year ago

Description

Similar to the existing testFile option, adding an option to the Jest executor that supports passing a list of tests files to run.

Motivation

The @nx/vite:test plugin seems to support this behavior already with testFiles, and it seems testFiles has replaced testFile, so this feature could bridge the functionality between the two test runners.

At Netlify, we use the circleci tests run command to split tests for parallelization and to utilize CircleCI's rerun failed tests feature. CircleCI's CLI will pass tests as a space-delimited list of files, so ideally we could easily hook into this behavior with a command like:

npx jest --listTests | circleci tests run --command="xargs npx nx run-many -t test --testFiles" --split-by=timings

Suggested Implementation

Add a new option called testFiles to the Jest executor that is either a string with the expectation that it's a space-delimited list of file names or to match the vitest plugin, an array of strings (I'm not sure how nx would parse this from the CLI).

Alternate Implementations

leosvelperez commented 6 months ago

hey @cmparsons! Thanks for the suggestion!

I'll look into adding support for this to the @nx/jest:jest executor. Please note that if you're using inferred tasks for Jest, you can already do this:

nx test <project> path/to/spec/file1 path/to/spec/file2
nx test <project> filename1 filename2
nx test <project> path/to/folder/containing/spec/files

The tasks inferred by the @nx/jest plugin run the Jest CLI directly jest from the project root as cwd. So, you're able to use anything the Jest CLI supports.

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it hasn't had any activity for 6 months. Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore. If at this point, this is still an issue, please respond with updated information. It will be closed in 21 days if no further activity occurs. Thanks for being a part of the Nx community! 🙏