Improve documentation about transformer and moduleNameMapper
See original GitHub issue🐛 Bug Report
The current documentation about is missing important details about transform
and moduleNameMapper
which would be crucial for understanding how to configure Jest.
To Reproduce
Steps to reproduce the behavior:
- Navigate to the configuration page
Expected behavior
I expected to understand
- Does
moduleNameMapper
transformation happens beforetransform
? - Does
transform
runs on files matched bymoduleNameMapper
? - Does the order of the
transform
keys matter for the pattern matching? If so- Does the file gets apply all the matching transformers or just the first matching as
moduleNameMapper
works?
- Does the file gets apply all the matching transformers or just the first matching as
Notes
Right now I am trying to add these two transformers
{
'\\.(js|jsx|ts|tsx)$': require.resolve('./transforms/babel.js'),
'^(?!\\.(js|jsx|ts|tsx|json))$': require.resolve('./transforms/file.js');
}
Since I don’t have a way to know if all the matching will get applied to the files, I am not sure if I have to ignore everything from the first transformer as I am doing today or match everything that didn’t match before.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Configuring Jest
Jest runs the code of your project as JavaScript, hence a transformer is needed if you use some syntax not supported by Node...
Read more >AST transformers option | ts-jest - GitHub Pages
This transformer works similar to moduleNameMapper in jest.config.js . When using this transformer, one might not need moduleNameMapper anymore.
Read more >Jest + Typescript + Absolute paths (baseUrl) gives error
This error occurs because of using absolute paths in the import statements of our TypeScript/Nest.js/Angular projects while using Jest. Fixing ...
Read more >Gatsby Changelog | 5.3.0
Better documentation explorer through search and markdown support; Plugin ecosystem. Want to learn more? Head to the Introducing GraphiQL docs. The plugin ...
Read more >Transformers: Basics, Maintenance, and Diagnostics
better understand how transformers work, how they are best maintained, and how to test and evaluate their condition. It has been.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@yordis I think it’s better to check that by experiment. And I think moduleNameMapper takes precedence over transform.
In project, I have ‘identity-obj-proxy’ moduleNameMapper. Tests work.
I have a custom transformer as well, which is broken by design. When moduleNameMapper is turned off it crashes as it should. When I turn on my mapper again, everything works like a charm.
I think this should serve as a proof that these two options are exclusive with moduleNameMapper taking precedence.
Waiting for some confirmation but seems
Does
moduleNameMapper
transformation happens beforetransform
? Yes, it happens when Jest try to mock the files.Does
transform
runs on files matched bymoduleNameMapper
? Yes, it seems that since thetransfomer
do not know about themoduleNameMapper
and viceversa, the transformers will actually transform the files matched bymoduleNameMapper