Im trying to set up a convention to ignore any test that follows a pattern. The filename would look like this if you wanted jest to ignore it during npm test.
DISABLED.MyComponent.test.js
trying to use testPathIgnorePatterns
testPathIgnorePatterns: ['<rootDir>/src/**/DISABLED.{*}.js'],
The error is either it is still being run, or it throws a error that the regex is invalid.
Jest uses glob patterns to match the test files, so prefixing the default entries in the testMatch
configuration with !(DISABLED.)
should do the job.
package.json
{
// ... rest of the package
"jest": {
"testMatch": [
"**/__tests__/**/!(DISABLED.)*.[jt]s?(x)",
"**/!(DISABLED.)?(*.)+(spec|test).[tj]s?(x)"
]
}
}
Side note: You can also "disable" the test file by renaming the main describe
block to xdescribe
or describe.skip
, which would give visibility that there are skipped tests instead of completely ignore the file
Test Suites: 1 skipped, 11 passed, 11 of 12 total
Tests: 2 skipped, 112 passed, 114 total
testPathIgnorePatterns
is an array of regex patterns that ignores any path that matches the listed expressions and should contain the default "/node_modules/"
as well. While it is not intended you may as well use testPathIgnorePatterns to exclude specific files:
So, your best bet would be to move the ignored test to s separate folder, e.g.
"jest": {
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/ignore/this/path/"
]
}
The other answers here are helpful but miss the core fact:
testPathIgnorePatterns
can be used to ignore your filenames. The problem is that testPathIgnorePatterns
takes a RegExp, not a glob as you've specified.
The default setting for testPathIgnorePatterns
is "/node_modules/"
, so it's probably useful to include it as well.
As an example, to ignore end to end tests that have an "e2e-" prefix, you could use:
"testPathIgnorePatterns": [
"/node_modules/",
"/e2e-"
]
In your specific case, this would be something like the following (note how the .
is escaped in /DISABLED\\.
):
"testPathIgnorePatterns": [
"/node_modules/",
"/DISABLED\\."
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With