Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify behavior of transformIgnorePatterns when including multiple patterns. #11796

Merged
merged 6 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,13 @@ If the tests are written using [native ESM](ECMAScriptModules.md) the transforme

Default: `["/node_modules/", "\\.pnp\\.[^\\\/]+$"]`

An array of regexp pattern strings that are matched against all source file paths before transformation. If the file path matches any of the patterns, it will not be transformed.
An array of regexp pattern strings that are matched against all source file paths before transformation. If the file path matches **any** of the patterns, it will not be transformed.

Patterns that overlap with each other may result in a file not being transformed unexpectedly. For example:
AndrewSouthpaw marked this conversation as resolved.
Show resolved Hide resolved

`["/node_modules/(?!foo|bar)", ".*/bar/"]`
AndrewSouthpaw marked this conversation as resolved.
Show resolved Hide resolved

The first matches any `node_modules` folders except for `node_modules/foo` and `node_modules/bar`, but the second one matches any with `bar` in the path. In this case, `node_modules/bar` will not be transformed.

These pattern strings match against the full path. Use the `<rootDir>` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories.

Expand Down
13 changes: 13 additions & 0 deletions docs/TutorialReactNative.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ By default the jest-react-native preset only processes the project's own source
}
```

Because `transformIgnorePatterns` will not transform a file if it matches **any** pattern provided, it is necessary to only use the above exclusion pattern only once. Otherwise, a folder that doesn't match in one pattern will match in the other. In the example below, neither module will be transformed:
AndrewSouthpaw marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"transformIgnorePatterns": [
"node_modules/(?!(foo)/)",
"node_modules/(?!(bar)/)"
AndrewSouthpaw marked this conversation as resolved.
Show resolved Hide resolved
]
}
```



### setupFiles

If you'd like to provide additional configuration for every test file, the [`setupFiles` configuration option](configuration#setupfiles-array) can be used to specify setup scripts.
Expand Down