-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to filter test cases in test files using a custom Jest runner #10288
Comments
Here is a working draft PR for the feature. I could use some help with resolving the failing tests i'm experiencing on master's head before it is ready for review. |
Based on PR feedback:
I'm going to try another approach to this that does not require using |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Updated: Draft PR available
🚀 Feature Proposal
Currently custom Jest runners support filtering test file paths, however it would also be nice to filter test cases in those test files.
Motivation
I'd like to setup my custom Jest runner to filter test cases by the test case's docBlock pragmas. Lets say I wanted to mark tests with a
@severity
pragma and wanted my custom Jest runner to only run@severity critical
test cases when provided a CLI arg I.e.jest run --severity=critical
Updated: Working project (dependent on Jest PR approval)
Example
Perfect world IMO would be to create a new API
TestRunner.runTestCases()
similar to theTestRunner.runTests()
.runTestCases()
would receive an array of Jest test cases for each file with properties similar to Circus'sTest.mode
which could be modified asvoid|'todo'|'skip'|'only'
before passing tosuper.runTestCases()
.Although it looks like the current implementation of jest-runner only handles the test paths and leaves the test file processing to the test framework (circus/jasmine). So perhaps another solution would be to expose the
testNamePattern
config in theTestRunner.runTests()
. The current implementation oftestNamePattern
only takes a single string/RegExp, ideally this would accept an array of test name patterns. A workaround for now could be to form a string composed of test names separated by the regex|
token I.e."(name of test 1|name of test 2)"
.I've tested this theory by adding the following Get/Set to the TestRunner class in
jest-runner/src/index.ts
:This allows me to set the testNamePattern in my custom Jest runner like this:
However this only works as expected if all test cases use unique names. One way to prevent test name collisions between files would be to enable setting the
testNamePattern
for each test file. This could be achieved by addingtestNamePattern
to the list ofProjectConfig
options, and modifying the respectedtestNamePattern
checks in both Jasmine and Circus. ThetestNamePattern
config would be utilized in the typical priority ofProjectConfig
>GlobalConfig
>Default(undefined)
. This would allow custom Jest runners to set a testNamePattern per test file passed throughTestRunner.runTests()
or it will fallback to the typical config.If this sounds like an acceptable path I can happily open a PR.
Pitch
This would enable custom Jest runners to have more control over what is ran. Enabling more customizable test runs which is especially useful when working with large test collections. This would also allow users to write and organize test cases in ways that are run-agnostic.
The text was updated successfully, but these errors were encountered: