question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 regexp
  • testMatch allows an array of globs
  • testPathIgnorePatterns 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
SimenBcommented, Oct 16, 2018

@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.

1reaction
rickhanloniicommented, Oct 16, 2018

All you @jamietre!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
An array of regexp pattern strings that are matched against all file paths before executing the test. If the file path matches any...
Read more >
Jest's testRegex and testMatch - Stack Overflow
jest.testMatch accepts an array of glob patterns. Like when you use ls p* to list every file in the current directory which starts...
Read more >
Configuring package.json · Jest
An array of regexp pattern strings that are matched against all file paths before executing the test. If the file path matches any...
Read more >
Configuring Jest - API Manual
If you'd like to use your package.json to store Jest's config, the "jest" key should be used ... testPathIgnorePatterns [array] · testRegex [string...
Read more >
Using with TypeScript - Vue Test Utils
js extension in the entire project. To run test files with a .ts extension, we need to change the testRegex in the config...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found