0

I am trying to get jest to tun my unit tests but not my integration tests. They live in the same folders along with the components they test. The unit tests have the filename pattern *.test.js, where the * is the component name. The integration tests have the pattern *.integration.test.js, where the * is the component name.

I'm bad with Regex. The best that I've come up with is:

(?!\bintegration\b)

This excludes all of the integration tests, but jest is now trying to run my index.js files. I need the expression to exclude 'integration, but include 'test'

xavier
  • 1,860
  • 4
  • 18
  • 46
Jon Lindell
  • 31
  • 1
  • 4

1 Answers1

0

My guess is that maybe here we might want an expression similar to:

(?=.*\bintegration\b.*)(?!.*\btest\b.*).*

Demo

const regex = /(?=.*\bintegration\b.*)(?!.*\btest\b.*).*/gm;
const str = `integration, but include 'test'
integration, but include 'tes
integration, but include 'tests
.integration.test.js
.integration.tests.js`;
let m;

while ((m = regex.exec(str)) !== null) {
    // This is necessary to avoid infinite loops with zero-width matches
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
}
Emma
  • 27,428
  • 11
  • 44
  • 69
  • No need to use two looakrounds, one will do. Also, check [Lookarounds (Usually) Want to be Anchored](https://www.rexegg.com/regex-lookarounds.html#anchor). – Wiktor Stribiżew Jun 20 '19 at 16:41
  • 2
    Thank you for the thorough answer. Unfortunately that expression doesn't work. This is in my jest config file, so I can't have a function, just an expression. The output from running the test is: testRegex: /(?=.integratio.*)(?!.tes.*).*/gm - 0 matches Pattern: - 0 matches – Jon Lindell Jun 20 '19 at 16:52