diff --git a/website/versioned_docs/version-25.x/Configuration.md b/website/versioned_docs/version-25.x/Configuration.md index dc100cfef6e7..1977013fc8f9 100644 --- a/website/versioned_docs/version-25.x/Configuration.md +++ b/website/versioned_docs/version-25.x/Configuration.md @@ -1208,16 +1208,35 @@ _Note: when adding additional code transformers, this will overwrite the default ### `transformIgnorePatterns` \[array<string>] -Default: `["/node_modules/"]` +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. -These pattern strings match against the full path. Use the `` 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. +Providing regexp patterns that overlap with each other may result in files not being transformed that you expected to be transformed. For example: -Example: `["/bower_components/", "/node_modules/"]`. +```json +{ + "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 `` 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: + +```json +{ + "transformIgnorePatterns": [ + "/bower_components/", + "/node_modules/" + ] +} +``` + ### `unmockedModulePathPatterns` \[array<string>] Default: `[]` diff --git a/website/versioned_docs/version-25.x/TutorialReactNative.md b/website/versioned_docs/version-25.x/TutorialReactNative.md index 5c806ff26bb9..a54914a45b45 100644 --- a/website/versioned_docs/version-25.x/TutorialReactNative.md +++ b/website/versioned_docs/version-25.x/TutorialReactNative.md @@ -136,9 +136,9 @@ The preset sets up the environment and is very opinionated and based on what we ### transformIgnorePatterns customization -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. +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 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 { @@ -148,6 +148,16 @@ By default the jest-react-native preset only processes the project's own source } ``` +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/)"] // not what you want +} +``` + ### 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. diff --git a/website/versioned_docs/version-26.x/Configuration.md b/website/versioned_docs/version-26.x/Configuration.md index 4091301b32f3..e916d032325d 100644 --- a/website/versioned_docs/version-26.x/Configuration.md +++ b/website/versioned_docs/version-26.x/Configuration.md @@ -1302,14 +1302,33 @@ _Note: when adding additional code transformers, this will overwrite the default 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. -These pattern strings match against the full path. Use the `` 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. +Providing regexp patterns that overlap with each other may result in files not being transformed that you expected to be transformed. For example: + +```json +{ + "transformIgnorePatterns": ["/node_modules/(?!(foo|bar)/)", "/bar/"] +} +``` -Example: `["/bower_components/", "/node_modules/"]`. +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 `` 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: + +```json +{ + "transformIgnorePatterns": [ + "/bower_components/", + "/node_modules/" + ] +} +``` + ### `unmockedModulePathPatterns` \[array<string>] Default: `[]` diff --git a/website/versioned_docs/version-26.x/TutorialReactNative.md b/website/versioned_docs/version-26.x/TutorialReactNative.md index 5c806ff26bb9..a54914a45b45 100644 --- a/website/versioned_docs/version-26.x/TutorialReactNative.md +++ b/website/versioned_docs/version-26.x/TutorialReactNative.md @@ -136,9 +136,9 @@ The preset sets up the environment and is very opinionated and based on what we ### transformIgnorePatterns customization -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. +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 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 { @@ -148,6 +148,16 @@ By default the jest-react-native preset only processes the project's own source } ``` +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/)"] // not what you want +} +``` + ### 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. diff --git a/website/versioned_docs/version-27.0/Configuration.md b/website/versioned_docs/version-27.0/Configuration.md index 9c2ab1e8d4d8..e8ba478bc65d 100644 --- a/website/versioned_docs/version-27.0/Configuration.md +++ b/website/versioned_docs/version-27.0/Configuration.md @@ -1332,14 +1332,33 @@ 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. -These pattern strings match against the full path. Use the `` 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. +Providing regexp patterns that overlap with each other may result in files not being transformed that you expected to be transformed. For example: + +```json +{ + "transformIgnorePatterns": ["/node_modules/(?!(foo|bar)/)", "/bar/"] +} +``` -Example: `["/bower_components/", "/node_modules/"]`. +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 `` 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: + +```json +{ + "transformIgnorePatterns": [ + "/bower_components/", + "/node_modules/" + ] +} +``` + ### `unmockedModulePathPatterns` \[array<string>] Default: `[]` diff --git a/website/versioned_docs/version-27.0/TutorialReactNative.md b/website/versioned_docs/version-27.0/TutorialReactNative.md index bba83bf1c291..760aaed02b4b 100644 --- a/website/versioned_docs/version-27.0/TutorialReactNative.md +++ b/website/versioned_docs/version-27.0/TutorialReactNative.md @@ -136,9 +136,9 @@ The preset sets up the environment and is very opinionated and based on what we ### transformIgnorePatterns customization -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. +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 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 { @@ -148,6 +148,16 @@ By default the jest-react-native preset only processes the project's own source } ``` +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/)"] // not what you want +} +``` + ### 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. diff --git a/website/versioned_docs/version-27.1/Configuration.md b/website/versioned_docs/version-27.1/Configuration.md index 58c1d6133852..9d6d8ebdd1cf 100644 --- a/website/versioned_docs/version-27.1/Configuration.md +++ b/website/versioned_docs/version-27.1/Configuration.md @@ -1367,14 +1367,33 @@ 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. -These pattern strings match against the full path. Use the `` 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. +Providing regexp patterns that overlap with each other may result in files not being transformed that you expected to be transformed. For example: + +```json +{ + "transformIgnorePatterns": ["/node_modules/(?!(foo|bar)/)", "/bar/"] +} +``` -Example: `["/bower_components/", "/node_modules/"]`. +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 `` 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: + +```json +{ + "transformIgnorePatterns": [ + "/bower_components/", + "/node_modules/" + ] +} +``` + ### `unmockedModulePathPatterns` \[array<string>] Default: `[]` diff --git a/website/versioned_docs/version-27.1/TutorialReactNative.md b/website/versioned_docs/version-27.1/TutorialReactNative.md index bba83bf1c291..760aaed02b4b 100644 --- a/website/versioned_docs/version-27.1/TutorialReactNative.md +++ b/website/versioned_docs/version-27.1/TutorialReactNative.md @@ -136,9 +136,9 @@ The preset sets up the environment and is very opinionated and based on what we ### transformIgnorePatterns customization -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. +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 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 { @@ -148,6 +148,16 @@ By default the jest-react-native preset only processes the project's own source } ``` +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/)"] // not what you want +} +``` + ### 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.