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

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

Closed
coffeebeats opened this issue Jan 14, 2023 · 2 comments · Fixed by #13770

Comments

@coffeebeats
Copy link
Contributor

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
@SimenB
Copy link
Member

SimenB commented Jan 24, 2023

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants