Skip to content

Problems overriding jest.transformIgnorePatterns #241

@Luismahou

Description

@Luismahou

Hi there!

First of all, thanks for this awesome project!

We use packages that are written in ES6. Jest by default doesn't transform anything inside node_modules unless transformIgnorePatterns is set. If jest is used without create-react-app the following configuration fixes the issue:

"jest": {
  "transformIgnorePatterns": ["/node_modules/(?!(@my-company)/).*/"]
}

NOTE: @my-company is used because all the packages are scoped.

When we use that configuration with create-react-app and react-app-rewired the final value for that option is:

["/node_modules/(?!(@my-company)/).*/", "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"]

Jest would run both regular expressions and if any of them is matched the file won't be transformed. The second regex matches all .js inside node_modules forcing jest to do not transform the files inside node_modules/@my-company.


I can think of a couple of solutions:

  1. Override transformIgnorePatters instead of append. My impression is that if anyone needs to modify this option, they will always want to avoid the default pattern.
  2. Use a special property to enable overriding. For example:
"jest": {
  "override": {
    "transformIgnorePatterns": ["..."]
  }
}

Please, let me know your thoughts. If you're happy with any of the solutions I'll submit a PR.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions