Skip to content

[Bug]: Multiple uses of a preprocessor in the transform option will have custom config overwritten #13769

Closed

Description

Version

29.3.1

Steps to reproduce

  1. Clone my repo at https://github.com/coffeebeats/example-jest-bug-overwrite-transform-config
  2. Review the README.md file to understand the bug and how to test.
  3. Run yarn install to install dependencies
  4. Update the jest.config.js file to enable one of the four provided scenarios
  5. Run yarn test to observe the effects of the jest.config.js file

Expected behavior

When I specify multiple transform entries in the Jest configuration object that (1) use the same preprocessor, (2) have differing match patterns, and (3) have differing custom preprocessor configurations, then I expect the correct preprocessor configuration to be used based on the file being transformed.

Consider the following transform object (note that this is a nonsensical configuration, meant only to illustrate the problem):

{
  ".+\.ts$": ["processor", CONFIG_1],
  ".+\.js$": ["processor", CONFIG_2],
}

When Jest transforms .ts files, then I expect processor to be used with CONFIG_1. Likewise, when .js files are transformed, then processor should be passed CONFIG_2.

Actual behavior

The latest entry of a given processor will always overwrite the configuration of all other uses of that processor. This means that, provided the same example above, whenever processor is used, it will always be passed CONFIG_2 (even for .ts files!).

Additional context

As mentioned in the example repository, this is caused by the transformCache and how it caches transformer configuration solely based on the preprocessor path.

Environment

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 19.4.0 - ~/.volta/tools/image/node/19.4.0/bin/node
    Yarn: 3.3.1 - ~/.volta/tools/image/yarn/3.3.1/bin/yarn
    npm: 9.2.0 - ~/.volta/tools/image/npm/9.2.0/bin/npm
  npmPackages:
    jest: 29.3.1 => 29.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions