Allow configuring using an array of `testRegex`
See original GitHub issue🚀 Feature Proposal
Creating dynamic configurations to include or exclude specific things is difficult because of inconsistency in how config allows specifying inclusions and exclusions.
testRegex
allows only a single regexptestMatch
allows an array of globstestPathIgnorePatterns
allows an array of regexps
So there’s no format (regex or glob) that can be used to build an array that works both for including and excluding.
It would be very convenient if either there were an analog to testMatch
for ignoring (an array of globs), or it were permissible to provide an array of regexps instead of only a single one for testRegex
.
I think the easiest solution to implement would be simply accepting an array or a single regexp for testRegex
. Additionally, the regexp array convention is much widely used already (coveragePathIgnorePatterns
, modulePathIgnorePatterns
, transformPathIgnorePatterns
, watchPathIgnorePatterns
, testPathIgnorePatterns
). Alternatively, a new config option testPathPatterns
could be introduced that only accepts an array, for consistency with all the ignore options, but it seems redundant.
I’d like to take a shot at coding it, but wanted to vet the feature idea before doing any work.
Motivation
Motivation is creating simple configuration that can be used to run buckets of tests that are dynamically specified by pattern matching. For example, I would like to be able to specify patterns that match slow tests, and be able to produce dynamic config that can both exclude only slow tests, or run only slow tests.
Example
jest.config.js
const mode = process.env.JEST_MODE;
let testRegex = [/__tests__/\.tsx*$/];
const testPatternIgnorePaths = []'
const slowTests = /__tests__/.*\.slow\.tsx*$/;
switch(mode) {
case 'slow':
testRegex = [slowTests];
break;
case 'fast':
testPatternIgnorePaths.push(slowTests);
break;
case default: // err
}
module.exports = {
testRegex,
testPatternIgnorePaths,
...
}
Pitch
Why does this feature belong in the Jest core platform?
It would be great for creating optimized configurations in large test environments. It makes the way file matching patterns are specified in configuration more consistent as well.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:13 (8 by maintainers)
Top GitHub Comments
@rickhanlonii @thymikee we just discussed config overhaul as it’s quite the hot mess, and the mess that is regex vs glob, separate ignore fields etc should definitely be on the chopping block.
A single issue going through all config options (and CLI options) might make sense, although I guess file matching is big enough to be discussed on its own (e.g. in this issue).
So to be on topic; for file matching, of the top of my head, this is my suggestion:
coveragePatterns: Array<Glob>
,testPatterns: Array<Glob>
,transformPatterns: Array<Glob>
and remove everything else.All you @jamietre!