Support Object transformer for transform and moduleNameMapper configs
See original GitHub issue🚀 Feature Proposal
Allow specifying a JavaScript object that represents the transformer on transform
and moduleNameMapper
configuration.
Motivation
I created a factory function that creates some Jest configurations. In the JavaScript section, I have something like this
transform: {
'\\.(js|jsx|ts|tsx)$': require.resolve('./transforms/babelTransform.js'),
}
Because the transforms are set up by specifying a file I lose the factory configuration when I call the function.
const createJestConfigFactory = (opts)=> {
return {
transforms: {
// this is not a function call so I lose the scope for `opts`
'\\.(js|jsx|ts|tsx)$': require.resolve('./transforms/babelTransform.js')
}
}
};
Example
An example of how this could be fixed:
const transformCreator = (opts)=> {
return {
// this object is a transformer
process: ()=> {
// ...
}
};
};
const createJestConfigFactory = (opts)=> {
return {
transforms: {
// this is not a function call so I lose the scope for `opts`
'\\.(js|jsx|ts|tsx)$': transformCreator(opts)
}
}
};
Pitch
Adding features like this one give more flexibility and power to advanced configurations.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
To have some of your "node_modules" files transformed, you ...
You don't need to add transformIgnorePatterns configuration for jest config, the node_modules folder is ignored by transformers.
Read more >Configuring Jest
The configuration file should simply export an object: JavaScript; TypeScript. /** @type {import('jest').Config} */
Read more >Configuring package.json · Jest
Jest's configuration can be defined in the package.json file of your project or through the --config <path/to/json> option.
Read more >out of the box jest supports babel, which will be used to ...
You don't need to add transformIgnorePatterns configuration for jest config, the node_modules folder is ignored by transformers. But this is not the issue....
Read more >Top 5 jest-config Code Examples - Snyk
To help you get started, we've selected a few jest-config examples, based on popular ways ... If we output a JSON object, we...
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 FreeTop 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
Top GitHub Comments
Specifying a transform directly instead of pointing to a module
Jest
requires seems like a great idea! We need to make sure it’s not an issue when serializing the config to and from workers, thoughThis 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.