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.

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

github_iconTop GitHub Comments

1reaction
SimenBcommented, Oct 21, 2018

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, though

0reactions
github-actions[bot]commented, May 2, 2022

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.

Read more comments on GitHub >

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

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