question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 before transform?
  • Does transform runs on files matched by moduleNameMapper?
  • 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?

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
PiotrSiatkowskicommented, Sep 23, 2019

@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.

1reaction
yordiscommented, Nov 28, 2018

Waiting for some confirmation but seems

  • Does moduleNameMapper transformation happens before transform? Yes, it happens when Jest try to mock the files.

  • Does transform runs on files matched by moduleNameMapper? Yes, it seems that since the transfomer do not know about the moduleNameMapper and viceversa, the transformers will actually transform the files matched by moduleNameMapper

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found