Jest cli testPathIgnorePatterns with jest.config.js results in No tests found

Viewed 3533

I want to run jest combining cli and jest.config.js, so I can use the same config but with minor changes at run time

jest --config=jest.config.js

Results in

Test Suites: 1 failed, 163 passed, 164 total
Tests:       8 skipped, 1685 passed, 1693 total
Snapshots:   87 passed, 87 total
Time:        34.719s, estimated 44s

While

jest --config=jest.config.js --testPathIgnorePatterns=[ignore]

Results in

752 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 164 matches
  testPathIgnorePatterns: [ignore] - 0 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches
error Command failed with exit code 1.

If I modify the config

modulePathIgnorePatterns: [
'<rootDir>/src/.*/__mocks__',
'<rootDir>/node_modules',
'<rootDir>/.*/ignore',
],

Results in

Test Suites: 163 passed, 163 total
Tests:       8 skipped, 1685 passed, 1693 total
Snapshots:   87 passed, 87 total
Time:        31.417s
2 Answers

The documentation states that testPathIgnorePatterns is an array. Arrays in shell are comma or space separated.

This works:

jest --config=jest.config.js --testPathIgnorePatterns=ignore

As would:

jest --config=jest.config.js --testPathIgnorePatterns=ignore,ignoreThisAsWell

As per @Tiago GouvĂȘa's comment on mummybot's answer, comma separated doesn't work everywhere.

For me, space separated and doubling the argument both work (I suspect the latter might be more consistently supported).

jest --config=jest.config.js --testPathIgnorePatterns=ignore --testPathIgnorePatterns=ignoreThisAsWell
Related