Skip to content

Commit

Permalink
More PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSouthpaw committed Sep 2, 2021
1 parent 35e6dc9 commit 5b13a37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/Configuration.md
Expand Up @@ -1373,12 +1373,14 @@ Providing regexp patterns that overlap with each other may result in files not b

```json
{
"transformIgnorePatterns": ["/node_modules/(?!foo|bar/)", "/bar/"]
"transformIgnorePatterns": ["/node_modules/(?!(foo|bar)/)", "/bar/"]
}
```

The first pattern will match (and therefore not transform) files inside `/node_modules` except for those in `/node_modules/foo/` and `/node_modules/bar/`. The second pattern will match (and therefore not transform) files inside any path with `/bar/` in it. With the two together, files in `/node_modules/bar/` will not be transformed because it does match the second pattern, even though it was excluded by the first.

Sometimes it happens (especially in React Native or TypeScript projects) that 3rd party modules are published as untranspiled. Since all files inside `node_modules` are not transformed by default, Jest will not understand the code in these modules, resulting in syntax errors. To overcome this, you may use `transformIgnorePatterns` to allow transpiling such modules. You'll find a good example of this use case in [React Native Guide](/docs/tutorial-react-native#transformignorepatterns-customization).

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.

Example:
Expand All @@ -1392,8 +1394,6 @@ Example:
}
```

Sometimes it happens (especially in React Native or TypeScript projects) that 3rd party modules are published as untranspiled. Since all files inside `node_modules` are not transformed by default, Jest will not understand the code in these modules, resulting in syntax errors. To overcome this, you may use `transformIgnorePatterns` to allow transpiling such modules. You'll find a good example of this use case in [React Native Guide](/docs/tutorial-react-native#transformignorepatterns-customization).

### `unmockedModulePathPatterns` \[array&lt;string&gt;]

Default: `[]`
Expand Down
8 changes: 5 additions & 3 deletions docs/TutorialReactNative.md
Expand Up @@ -138,21 +138,23 @@ The preset sets up the environment and is very opinionated and based on what we

The [`transformIgnorePatterns`](configuration#transformignorepatterns-arraystring) option can be used to specify which files shall be transformed by Babel. Many `react-native` npm modules unfortunately don't pre-compile their source code before publishing.

By default the `jest-react-native` preset only processes the project's own source files and `react-native`. If you have npm dependencies that have to be transformed you can customize this configuration option by including modules other than `react-native` by separating them with the `|` operator:
By default the `jest-react-native` preset only processes the project's own source files and `react-native`. If you have npm dependencies that have to be transformed you can customize this configuration option by including modules other than `react-native` by grouping them and separating them with the `|` operator:

```json
{
"transformIgnorePatterns": [
"node_modules/(?!react-native|my-project|react-native-button/)"
"node_modules/(?!(react-native|my-project|react-native-button)/)"
]
}
```

You can test which paths would match (and thus be excluded from transformation) with a tool [like this](https://regex101.com/r/JsLIDM/1).

`transformIgnorePatterns` will exclude a file from transformation if the path matches against **any** pattern provided. Splitting into multiple patterns could therefore have unintended results if you are not careful. In the example below, the exclusion (also known as a negative lookahead assertion) for `foo` and `bar` cancel each other out:

```json
{
"transformIgnorePatterns": ["node_modules/(?!foo/)", "node_modules/(?!bar/)"]
"transformIgnorePatterns": ["node_modules/(?!foo/)", "node_modules/(?!bar/)"] // not what you want
}
```

Expand Down

0 comments on commit 5b13a37

Please sign in to comment.