Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore a specific folder pattern in testMatch with Jest

I'm trying to ignore a specific folder in the testMatch pattern of Jest.

I have my tests in a __tests__ folder and I want to be able to have a folder __config__ into it with all files inside which should be ignored.

/__tests__
  /__config__
    someConfig.jsx
  /MyComponent.jsx
/MyComponent.jsx

My tests in the __tests__ folder will import the files from the __config__ folder so I don't want to ignore them with the transformIgnorePatterns.

But if I don't ignore the folder, Jest tries to run in the folder and returns an error:

FAIL src/components/__tests__/__config__/someConfig.jsx

Your test suite must contain at least one test.

I've tried a few different patterns but I can't find a way to ignore the __config__ folder

testMatch: [
  "**/__tests__/!(__config__)/**/*.(js)?(x)", // Doesn't work
  "**/__tests__/(**|!__config__)/*.(js)?(x)", // Doesn't work
  "**/__tests__/(**|?!__config__)/*.(js)?(x)", // Doesn't work
  "**/__tests__/{**,!__config__}/*.(js)?(x)", // Doesn't work
],

Any idea how I can ignore the sub-folder like this?

like image 917
alexmngn Avatar asked Dec 14 '17 18:12

alexmngn


1 Answers

Try to use testPathIgnorePatterns, instead.

If the test path matches any of the patterns, it will be skipped.

Use the string token to include the path to your project's root.

like image 134
GibboK Avatar answered Oct 12 '22 01:10

GibboK